Spring5中SpringWebContext方法过时的解决方案
Spring5 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());
SpringWebContext在Spring5中报错
想把页面信息全部获取出来存到redis缓存中,用
SpringWebContext ctx = new SpringWebContext(request, response, request.getServletContext(), request.getLocale(), model.asMap(), applicationContext);
代码报错,
解决办法(SpringWebContext在spring5中过时)
//手动渲染 IWebContext ctx =new WebContext(request,response, request.getServletContext(),request.getLocale(),model.asMap());
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
springboot集成spark并使用spark-sql的示例详解
这篇文章主要介绍了spring-boot集成spark并使用spark-sql的方法,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2022-02-02SpringBoot整合screw实现自动生成数据库设计文档
使用navicat工作的话,导出的格式是excel不符合格式,还得自己整理。所以本文将用screw工具包,整合到springboot的项目中便可以自动生成数据库设计文档,非常方便,下面就分享一下教程2022-11-11Spring中@Import的各种用法以及ImportAware接口详解
这篇文章主要介绍了Spring中@Import的各种用法以及ImportAware接口详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2019-10-10
最新评论