主要代碼html
一 配置文件——追加配置項spring
springMVC-servlet.xmlpost
<!-- thymeleaf的視圖解析器 -->spa
<bean id="templateResolver"orm
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">xml
<property name="prefix" value="/WEB-INF/html/" />htm
<property name="suffix" value=".html" />servlet
<property name="templateMode" value="HTML5" />it
</bean>io
<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>