最新版本WebContext构造函数-避坑
目录
最新版本WebContext构造函数-避坑
import org.thymeleaf.context.IWebContext;
import org.thymeleaf.context.WebContext;当你想把页面信息全部获取出来存到redis缓存中使用时,SpringWebContext在Spring5中报错
SpringWebContext ctx = new SpringWebContext(request, response,
request.getServletContext(), request.getLocale(), model.asMap(), applicationContext);代码报错1,很早版本之前的解决办法如下(SpringWebContext在spring5中过时)
//手动渲染
IWebContext ctx =new WebContext(request,response,
request.getServletContext(),request.getLocale(),model.asMap());但是最新版本仍然报错

根据WebContext提示

解决办法如下
IWebContext ctx =new WebContext(
(IWebExchange) request.getServletContext(),request.getLocale(),Map.of("user",user,"itemList",itemList));