MVC利用th属性实现用静态页面html来实现jsp页面输出


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




转载于:https://my.oschina.net/u/2411775/blog/479305

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值