配置thymeleaf视图解析器
时间: 2023-08-26 20:13:30 浏览: 137
Spring Boot应用配置常用相关视图解析器详解
在Spring MVC的配置文件中,配置Thymeleaf视图解析器的步骤如下所示:
1. 引入Thymeleaf的依赖到项目中。可以在pom.xml文件中添加以下依赖信息:
```xml
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
<version>3.0.13.RELEASE</version>
</dependency>
```
2. 在Spring MVC的配置文件中配置Thymeleaf视图解析器。可以使用以下XML配置:
```xml
<!-- 配置Thymeleaf视图解析器 -->
<bean id="viewResolver" class="org.thymeleaf.spring5.view.ThymeleafViewResolver">
<property name="order" value="1"/>
<property name="characterEncoding" value="UTF-8"/>
<property name="templateEngine">
<bean class="org.thymeleaf.spring5.SpringTemplateEngine">
<property name="templateResolver">
<bean class="org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver">
<!-- 视图前缀 -->
<property name="prefix" value="/WEB-INF/templates/"/>
<!-- 视图后缀 -->
<property name="suffix" value=".html"/>
<property name="templateMode" value="HTML5"/>
<property name="characterEncoding" value="UTF-8" />
</bean>
</property>
</bean>
</property>
</bean>
```
通过以上配置,你可以使用Thymeleaf作为Spring MVC的视图解析器,并指定视图文件的前缀和后缀。在这个示例中,视图文件的前缀是`/WEB-INF/templates/`,后缀是`.html`。请根据你的项目需求修改这些配置信息。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* [SpringMVC总结](https://blog.csdn.net/zhiwenganyong/article/details/128764283)[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^chatsearchT3_1"}} ] [.reference_item]
- *2* *3* [springmvc配置thymeleaf视图解析器](https://blog.csdn.net/m0_51620667/article/details/121731032)[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^chatsearchT3_1"}} ] [.reference_item]
[ .reference_list ]
阅读全文