0
点赞
收藏
分享

微信扫一扫

Thymeleaf手动渲染


为提高页面访问速度,可缓存html页面,客户端请求从缓存获取,获取不到再手动渲染

在spring4下

import org.thymeleaf.spring4.context.SpringWebContext;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;

@Autowired
private ThymeleafViewResolver thymeleafViewResolver;

SpringWebContext ctx = new SpringWebContext(request, response, request.getServletContext(), request.getLocale(),
model.asMap(), applicationContext);
// 手动渲染
html = thymeleafViewResolver.getTemplateEngine().process("这里写html页面名称", ctx);

在spring5

import org.thymeleaf.context.WebContext;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;


@Autowired
private ThymeleafViewResolver thymeleafViewResolver;


WebContext ctx = new WebContext(request,response,request.getServletContext(),request.getLocale(),model.asMap());
// 手动渲染
html = thymeleafViewResolver.getTemplateEngine().process("这里写html页面名称", ctx);



举报

相关推荐

0 条评论