主要代码
一 配置文件——追加配置项
springMVC-servlet.xml
<!-- thymeleaf的视图解析器 -->
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/html/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
</bean>
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
</bean>
<bean id="viewResolverThymeleaf" class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
<property name="characterEncoding" value="UTF-8"/>
<property name="order" value="0"/>
</bean>
二 将例子改写成HTML
helloWorld.html
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<form action="init" th:object="${UserBean}" method="post">
<button type="submit" name="login">检索</button>
</form>
login.html
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<body>
<div th:each="user,status:${list}">
<table>
<tr>
<td>ID:<a th:href="@{delete?(userId=${user.userId})}"><span th:text="${user.userId}">12</span></a></td>
<td>用户名:<span th:text="${user.userName}">123 </span></td>
</tr>
</table>
</div>
</body>