Springboot官方推荐的Themeleaf提供自动渲染模板页功能:
public class ThymeleafProperties {
private static final Charset DEFAULT_ENCODING;
public static final String DEFAULT_PREFIX = "classpath:/templates/";
public static final String DEFAULT_SUFFIX = ".html";
}
同时我们需要在porn.xml中引入Themeleaf的依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.1.11.RELEASE</version>
</dependency>
SpringBoot的静态资源默认会从
classpath:/resources,clsspath:/static/,classpath:/public/,classpath:/META-INF/resources/四个地址下寻找:
registry.addResourceHandler("/**").addResourceLocation(
"classpath:/META-INF/resources/","classpath:/static/",
"classpath:/static/","classpath:/public/")

本文总结了SpringBoot中视图解析的工作原理,包括官方推荐的Thymeleaf模板渲染,以及如何在配置文件中引入Thymeleaf依赖。SpringBoot默认的静态资源路径包括四个目录。在请求转发和重定向方面,详细阐述了直接返回视图、forward转发、redirect重定向的不同处理方式,以及它们与Thymeleaf模板渲染的关系。同时提到Thymeleaf在处理前端地址请求时的动态配置功能,如webjars和表单请求地址。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



