为工程添加组件+改写JSP页面为HTML文件

本文介绍如何在Spring MVC项目中配置并使用Thymeleaf模板引擎,包括配置文件设置、创建HTML页面及使用Thymeleaf语法实现动态内容展示。

主要代码

一   配置文件——追加配置项

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>



转载于:https://my.oschina.net/u/2411768/blog/479363

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值