1.thymeleaf 标签获取 contextPath:
<script type="text/javascript" th:inline="javascript"> /*<![CDATA[*/ contextPath = /*[[@{/}]]*/ ''; /*]]>*/ </script>2、thymeleaf 循环标签
info 为循环变量,在循环中使用info点属性即可<tr th:each="info:${list}">
3、thymeleaf 使用 href标签带参数:
<a class="acicon" th:href="@{/attendanceRecord/userAttendanceRecordListPage(userInfoId=${attendanceRecordDTO.userInfoId})}">4、thymeleaf 中将值传给 事件函数:
<a class="acicon" ><img th:src="@{/img/common/listedit.png}" th:name="${userInfo.userInfoId}" οnclick="editUserInfoPage(this)"/></a>
然后 $(this).attr('name');获取name的值 这个方法有点臃肿 不过能实现
5、循环给select 赋值:
<select name="areaInfoId" class="selectpicker" οnchange="setCity(this)"> <option>请选择省</option> <option th:each="areaInfo : ${areaInfos}" th:value="${areaInfo.areaInfoId}" th:text="${areaInfo.areaName}"></option> </select>6、给select动态选中:
<select name="enableFlag" class="selectpicker" οnchange="setAreaName()"> <option value="true" th:if="${userInfo.enableFlag ==true}" th:selected="selected">是</option> <option value="false" th:if="${userInfo.enableFlag ==false}" th:selected="selected">否</option> <option value="true" th:if="${userInfo.enableFlag ==false}">是</option> <option value="false" th:if="${userInfo.enableFlag ==true}">否</option> </select>
7、路径信息:
<script type="text/javascript" th:src="@{/js/basis/jquery/jquery-1.10.2.min.js}"></script>
<link rel="stylesheet" type="text/css" th:href="@{/style/basis/bootstrap/bootstrap3.min.css}"/>
8、字符串拼接:
<td th:text="${info}+'str'"></td>注意双引号是必须要有的
9、使用thymeleaf控制 单选框
<ul> <li class="fl"> <input type="radio" name="enableFlag" th:checked="${userInfo.enableFlag== true}" value="true" style="margin: 10px;"/> <label class="iRadioLable" style="width:auto; max-width:auto;margin: 0">是</label> </li> <li class="fl"> <input type="radio" name="enableFlag" th:checked="${userInfo.enableFlag==false}" value="false" style="margin: 10px"/> <label class="iRadioLable" style="width:auto; max-width:auto;margin: 0">否</label> </li> </ul>
10、thymeleaf中使用三目运算
<td th:text="${imposeOccupyInfo.certificateCode== null} ? '-':${imposeOccupyInfo.certificateCode}"></td>
11、thymeleaf中动态控制class 样式
<li th:class="${enterpriseInfo.creditGrade gt iterStat.index}?'start':''"></li>
12、thymeleaf中使用时间格式化
<td th:text="${#dates.format(enterpriseInfo.insertTime,'yyyy-MM-dd')}"></td>