1.注入
@Autowired
ThymeleafViewResolver thymeleafViewResolver;
2.接口
@GetMapping("/a")
@ResponseBody
public String handle(@RequestParam Boolean flag ,HttpServletRequest request,
HttpServletResponse response, Model model) {
if(flag) {
//手动渲染
IWebContext ctx = new WebContext(request,response,
request.getServletContext(),request.getLocale(), model.asMap());
return thymeleafViewResolver.getTemplateEngine().process("页面", ctx);
}else {
return "json";
}
}
网友评论