Thymeleaf 模板使用 Error resolving template "/home", template might not exist or might not be accessible by any of the

和属性文件中thymeleaf模板的配置相关

1、配置信息

spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.content-type=text/html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.cache=false
spring.thymeleaf.cache-period=0
spring.template.cache=false

2、在spring mvc 的 controller中

@RequestMapping("/home")
public String home(Model model, HttpServletRequest req) {
  model.addAttribute("access_token", req.getParameter("access_token"));
   return "home";
}

3、配置 + controller中必须为:

classpath:/templates/home   //classpath路径下的 templates包 下的 home.html文件

 

原文地址:https://www.cnblogs.com/zxguan/p/8417603.html