thymeleaf注入springboot需要引入jar:
org.springframework.boot spring-boot-starter-thymeleaf 2.1.0.RELEASE net.sourceforge.nekohtml nekohtml 1.9.22
在application.properties中添加:
#启动检查spring.thymeleaf.check-template=true#模板spring.thymeleaf.prefix=classpath:/templates/#文件后缀spring.thymeleaf.suffix=.htmlspring.thymeleaf.mode=LEGACYHTML5spring.thymeleaf.encoding=UTF-8spring.thymeleaf.content-type=text/htmlspring.thymeleaf.cache=falsespring.mvc.view.prefix=/resources/templates/spring.mvc.view.suffix=.htmlspring.mvc.static-path-pattern=/static/**#spring.resources.static-locations=classpath:/static/
异常错误:
1. Cannot find template location: classpath:/templates/
如果在程序中已经引入templates在application.properties中也引入了thymeleaf则:
问题出在pom.xml resource在移动资源文件时, templates被忽略所致。
src/main/resources *.*
static/**
template/**
true src/main/resources false
2. 同时注意程序的统一拦截器拦截要加载放行
参见拦截器配置方面。
3. 静态资源第一次设置在页面访问可能出现404,可对mvn先进行打包后,再试。