1、在login.html页面中键入关键代码
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<div th:each="userInfo,status:${list}">用th属性利用list引入数据库信息表
<table>
<tr>利用th 加入链接的格式<a th:href="@{delete?(userId=${userInfo.userId})}"></a>
<td><a th:href="@{delete?(userId=${userInfo.userId})}"><span th:text="${userInfo.userId}"></span></a></td>
th是一个属性而不是一个标签,所以需要用到标签来引入,不可直接使用(eg、span)
<td><span th:text="${userInfo.userName}"></span></td>
</tr>
</table>
</div>
2、在HelloWorld中键入关键代码
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>Insert title here</title>
</head>
<body>
<form action="init" th:object="${UserBean}" method="post">
<input name="UserId" type="text"/>
<button type="sumbit" name="check">检索</button>
</form>
</body>
</html>
3、在配置文件springMVC-servlet.xml中加入th解析包的配置文件
<!-- 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>
4、在lib中导入3个包
有:thymeleaf-2.1.4.RELEASE.jar
thymeleaf-spring4-2.1.4.RELEASE.jar
unbescape-1.1.0.RELEASE.jar