Springboot 配置视图解析器
时间: 2024-03-15 10:16:55 浏览: 88
在Spring Boot中配置视图解析器需要在application.properties或application.yml中添加以下配置:
1. 使用Thymeleaf作为模板引擎的情况下,配置如下:
application.properties:
```
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
```
application.yml:
```
spring:
thymeleaf:
prefix: classpath:/templates/
suffix: .html
```
2. 使用Freemarker作为模板引擎的情况下,配置如下:
application.properties:
```
spring.freemarker.template-loader-path=classpath:/templates/
spring.freemarker.suffix=.ftl
```
application.yml:
```
spring:
freemarker:
template-loader-path: classpath:/templates/
suffix: .ftl
```
3. 使用Velocity作为模板引擎的情况下,配置如下:
application.properties:
```
spring.velocity.resource-loader-path=classpath:/templates/
spring.velocity.suffix=.vm
```
application.yml:
```
spring:
velocity:
resource-loader-path: classpath:/templates/
suffix: .vm
```
其中,`prefix`表示模板文件的路径,`suffix`表示模板文件的扩展名。以上是常见的三种模板引擎的配置方式,可以根据实际情况选择配置。
阅读全文
相关推荐


















