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

时间:2024-12-02 20:36:08

和属性文件中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-
spring.thymeleaf.cache=false
spring.thymeleaf.cache-period=
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文件