springboot的thymeleaf配置
时间: 2023-10-20 14:00:19 浏览: 44
Spring Boot使用Thymeleaf作为模板引擎,默认不支持JSP。要配置Spring Boot的Thymeleaf,有以下几个步骤:
1. 在application.properties或application.yml文件中添加Thymeleaf模板的配置,包括模板路径、后缀、编码等。示例配置如下:
- application.properties配置:
```
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
```
- application.yml配置:
```
spring:
thymeleaf:
prefix: classpath:/templates/
suffix: .html
mode: HTML5
encoding: UTF-8
content-type: text/html
cache: false
```
2. 在项目的pom.xml文件中引入Thymeleaf依赖,示例配置如下:
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
```
以上就是配置Spring Boot的Thymeleaf的步骤。通过配置Thymeleaf,可以在Spring Boot中使用Thymeleaf来渲染HTML模板。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Springboot+Thymeleaf配置与使用](https://blog.csdn.net/qincidong/article/details/76126060)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [springBoot整合thymeleaf(超简单)](https://blog.csdn.net/m0_67403013/article/details/126115043)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]