1. 程式人生 > >thymeleaf 學習筆記(填坑)

thymeleaf 學習筆記(填坑)

1.thymeleaf 標籤獲取 contextPath:

<script type="text/javascript" th:inline="javascript">
/*<![CDATA[*/
contextPath = /*[[@{/}]]*/ '';
/*]]>*/
</script>
2、thymeleaf 迴圈標籤
<tr th:each="info:${list}">
info 為迴圈變數,在迴圈中使用info點屬性即可

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}" onclick="editUserInfoPage(this)"/></a>
然後 $(this).attr('name');獲取name的值 這個方法有點臃腫 不過能實現

5、迴圈給select 賦值:

<select  name="areaInfoId" class="selectpicker" onchange=
"setCity(this)"> <option>請選擇省</option> <option th:each="areaInfo : ${areaInfos}" th:value="${areaInfo.areaInfoId}" th:text="${areaInfo.areaName}"></option> </select>
6、給select動態選中:
<selectname="enableFlag" class="selectpicker" onchange="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>