找不到模板异常
异常信息:
Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers
查看ThymeleafProperties类(位于org.springframework.boot.autoconfigure.thymeleaf)中发现:
public class ThymeleafProperties {
private static final Charset DEFAULT_ENCODING;
public static final String DEFAULT_PREFIX = "classpath:/templates/";
public static final String DEFAULT_SUFFIX = ".html";
private boolean checkTemplate = true;
private boolean checkTemplateLocation = true;
private String prefix = "classpath:/templates/";
private String suffix = ".html";
private String mode = "HTML";
模板文件的默认读取路径classpath:/templates/ 下的html文件,所以将模板文件放到resources下的templates文件下即可解决;或者手动重新配置thymeleaf的读取路径,配置属性和ThymeleafProperties中的属性对应。
spring:
thymeleaf:
prefix: classpath:/ #修改成你需要的路径即可
suffix: .html
mode: HTML