引入thymeleaf依赖后不配置controller情况下,默认index文件访问到templete目录下,而不是静态文件夹static下

1.未进行任何controller配置
2.只引入了thymeleaf配置
3.配置了mvc.static-path-pattern: /static/**
4.未对thymeleaf进行任何自定义配置
现象:
当static文件夹与templete目录下同时存在index.html页面时,访问到templete文件夹下的Index.html

thymeleaf默认的目录就是classpath:/templates/,默认的文件后缀就是.html

@ConfigurationProperties(prefix = "spring.thymeleaf")
public class ThymeleafProperties {

	private static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8;

	public static final String DEFAULT_PREFIX = "classpath:/templates/";

	public static final String DEFAULT_SUFFIX = ".html";

...

跟静态文件冲突了,你可以设置模板的一些属性来进行规避试试看。例如:后缀

https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.templating.spring.thymeleaf.cache

非常感谢您的解答,我通过您的讲解解决了此问题!

1 个赞