spring-boot-starter-thymeleaf的yml配置 代码写出来
时间: 2023-11-27 17:05:43 浏览: 43
以下是一个基本的spring-boot-starter-thymeleaf的yml配置:
```yml
spring:
thymeleaf:
prefix: classpath:/templates/
suffix: .html
cache: false
mode: HTML
```
其中,`prefix`表示模板文件所在的路径,`suffix`表示模板文件的后缀名,`cache`表示是否开启缓存,`mode`表示模板模式(默认为HTML)。
相关问题
加了<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>后resource下面没有templastes包
这是因为在Spring Boot中,如果没有在application.properties或application.yml文件中进行配置,它默认会在classpath:/templates/下查找模板文件。如果你想使用模板引擎,可以在resource目录下手动创建templates目录,并将模板文件放在该目录下即可。另外,如果你想更改默认的模板文件位置,可以在配置文件中添加如下配置:
```
spring:
thymeleaf:
prefix: classpath:/templates/
```
这里以thymeleaf模板引擎为例进行说明。如果你使用的是其他的模板引擎,可以参考对应的配置方式。
springMVC项目如何整合thymeleaf和element-ui
整合Thymeleaf和Element-UI,需要在SpringMVC项目中配置Thymeleaf模板引擎和Element-UI前端框架。
首先,在Spring MVC项目中引入Thymeleaf和Element-UI的依赖。可以在pom.xml文件中添加以下依赖:
```xml
<dependencies>
<!-- Thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- Element-UI -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator-core</artifactId>
<version>0.40</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>element-ui</artifactId>
<version>2.10.1</version>
</dependency>
</dependencies>
```
然后,在Spring MVC配置文件中配置Thymeleaf模板引擎。可以在application.properties或application.yml文件中添加以下配置:
```properties
# Thymeleaf
spring.thymeleaf.mode=HTML
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html;charset=UTF-8
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.template-resolver-order=1
spring.thymeleaf.view-names=*
spring.thymeleaf.check-template-location=true
```
最后,在Thymeleaf模板中使用Element-UI的组件。可以在HTML文件中添加以下代码:
```html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:t="http://www.thymeleaf.org/extras/thymeleaf-spring4"
xmlns:el="http://www.thymeleaf.org/extras/element-ui"
lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!-- Element-UI -->
<link rel="stylesheet" href="/webjars/element-ui/2.10.1/theme-chalk/index.css">
<script src="/webjars/element-ui/2.10.1/index.js"></script>
</head>
<body>
<!-- 使用Element-UI的组件 -->
<el-button>Button</el-button>
</body>
</html>
```
以上就是整合Thymeleaf和Element-UI的步骤,希望能对你有所帮助!
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)