栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot将页面做缓存的坑(thymeleaf)解决SpringWebContext方法过时以及thymeleaf抓取信息

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot将页面做缓存的坑(thymeleaf)解决SpringWebContext方法过时以及thymeleaf抓取信息

    private  final ThymeleafViewResolver thymeleafViewResolver;//获取html返回元素
    private  final  ApplicationContext applicationContext;

 //手动渲染
    	SpringWebContext ctx = new SpringWebContext(request,response,
    			request.getServletContext(),request.getLocale(), model.asMap(), applicationContext );
    	html = thymeleafViewResolver.getTemplateEngine().process("goods_list", ctx);

在原有的springboot版本不一致的情况下SpringWebContext方法过时导致报错

解决方案:
这时候官网文档有新的替换版本:

 private  final ThymeleafViewResolver thymeleafViewResolver;//获取html返回元素

    //点击转换pdf
    @RequestMapping(value = "/pdfTransition2", produces="text/html")
    @ResponseBody
    public void pdfTransition2(@RequestParam String url, Model model, HttpSession session, HttpServletRequest request, HttpServletResponse response){
        System.out.println(url);
        Map map = productPdfService.selectCoaInfo(url);
        Object coa = map.get("coa");
        model.addAttribute("coa", coa);
        //手动获取网页信息可处理为pdf以及或作为缓存
        WebContext springWebContext = new WebContext(request,response,request.getServletContext(),request.getLocale(),model.asMap());
        String html = thymeleafViewResolver.getTemplateEngine().process("/product/detail-coa.html", springWebContext);//获取html返回元素
        
        System.out.println(html);

    }

https://juejin.cn/post/6844903847349977102
https://blog.csdn.net/WilsonSong1024/article/details/81535860

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/282300.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号