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>