1 <div th:with="param1=1"> 2 <a th:href="@{/link(p1=${param1})}">link</a> 3 </div>
【thymeleaf】模板中定义变量
th:with 定义变量
使用 th:with 定义变量。形如:
1 <th:block th:with="var1=1"></th:block> 2 <div th:with="var1=1"></div> 3 ...
使用方式如下:
1 <div th:with="param1=1">
2 <a th:href="@{/link(p1=${param1})}">link</a>
3 </div>
=================================================================
例如: 登录人对应的省份:北京, 列表下所有省份数据, 只有省份为:登录人的省份, 此数据[删除]按钮才可用
controller
model.addAttribute("provinceCode", getCurrentUser().getDataPermProvince().get(0));// 用户省
model.addAttribute("caseFileList", reportService.selectCaseBaseManageList(caseFile, getCurrentUser(), pageInfo));
html
<tr th:each="order, status: ${caseFileList}">
<td align="center">
<div th:with="provCode = ${provinceCode}">
<a th:unless="${order.provCode eq provCode}"
style="color:gray; text-decoration:none;" href ="javascript:return false;"> 删除</a>
<a th:if="${order.provCode eq provCode}"
href="javascript:void(0);" data-toggle="modal"
th:onclick="'javascript:deleteConfirm(\''+${order.id}+'\',\''+${order.provName}+'\',\''+${order.caseType}+'\',\''+${order.caseFileName}+'\',\''+${order.uploadUser}+'\',\''+${#dates.format(order.submitTime,'yyyy-MM-dd')}+'\')'"
data-target="#deleteConfirmModal">
删除
</a>
</div>
</td>
</tr>