解决Sping5中SpringWebContext方法过时

Sping5中SpringWebContext方法过时

为了优化访问速度,应对高并发,想把页面信息全部获取出来存到redis缓存中,这样每次访问就不用客户端进行渲染了,速度能快不少。

thymeleafViewResolver.getTemplateEngine().process("goodslist.html",ctx);

里面的ctx参数,这个参数就是WebContext

然后定义这个变量

SpringWebContext ctx = new SpringWebContext()

但是发现无法调用到,因为项目使用的是thymeleaf.spring5的版本

org.thymeleaf.spring4下面没有相同类型的,

因为在thymeleaf.spring5的API中把大部分的功能移到了IWebContext下面,用来区分边界。剔除了ApplicationContext 过多的依赖,现在thymeleaf渲染不再过多依赖spring容器

调用这个即可

IWebContext ctx =new WebContext(request,response,
                request.getServletContext(),request.getLocale(),model.asMap());

猜你喜欢

转载自blog.csdn.net/ouzhuangzhuang/article/details/84839266
今日推荐