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



