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<String, Object> 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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值