th:href
<a th:href="@{'/pageController?pageNum='+${pageNum}}" th:text="${pageNum}"></a>
格式:th:href="@{‘字符串’+${model中的nam值}}"。
controller取值
@RequestMapping(value = "/pageController",method = RequestMethod.GET)
public String pageController(Model model, HttpServletRequest request){
String pageNum = request.getParameter("pageNum");
th:src
th:src="@{/dist/img/admin.jpg}" 默认路径为static下面的
th:text下字符串拼接
user.name从后台传来的变量,${user.name}获得变量值。文本链接:用“+”符号,也可以用“|”符号。
若user.name=“张三”,解析结果为:Welcome,张三
<span th:text="'Welcome,'+${user.name}">
<span th:text="|Welcome, ${user.name}|">
th:action字符串拼接
若user.userId=1,解析结果为:
<form th:action="@{'/user/'+${user.userId}}"></form>
<form th:action="@{/user/{userId}(userId=${user.userId})}"></form>
th:if根据值判断是否显示标签
<div th:if="${hotel.chainName}!='No chain'">
</div>
这个就是根据hotel.chainName的值是否为’No chain’判断是否显示,如果是的话就不显示,不是的话就显示
th:each从List中取值循环显示
<tr th:each="hotelinfo : ${hotels}">
<td th:text="${hotelinfo.hotelId}">
</td>
<td th:text="${hotelinfo.hotelTranslatedName}">
</td>
<td th:text="${hotelinfo.addressline}">
</td>
<td>
<a th:href="@{'/user/hotelInfo?hotel_id='+ ${hotelinfo.hotelId}}">
<button type="button" class="btn btn-block btn-info hotel-info-btn">详情</button>
</a>
</td>
</tr>
th:each中取List值如何有个限制如n:m
th:each属性用于迭代循环,语法:th:each="obj,iterStat:${objList}"
迭代对象可以是java.util.List,java.util.Map,数组等;
iterStat称作状态变量,属性有:
index:当前迭代对象的index(从0开始计算)
count: 当前迭代对象的index(从1开始计算)
size:被迭代对象的大小
current:当前迭代变量
even/odd:布尔值,当前循环是否是偶数/奇数(从0开始计算)
first:布尔值,当前循环是否是第一个
last:布尔值,当前循环是否是最后一个
声明片段的时候 ,可以声明变量参数,在片段中使用变量参数
<span th:text="'Welcome,'+${user.name}">
<span th:text="|Welcome, ${user.name}|">
<form th:action="@{'/user/'+${user.userId}}"></form>
<form th:action="@{/user/{userId}(userId=${user.userId})}"></form>
switch和case条件判断
<div th:switch="${user.role}">
<p th:case="'admin'">User is an administrator</p>
<p th:case="#{roles.manager}">User is a manager</p>
</div>
th中datas.format将后端传来的日期数据进行格式化
th:text="${#dates.format(h_order.getoOrdertime(), 'yyyy-MM-dd')