thymeleaf 簡單應用

cason6810發表於2019-03-07

th:switch 應用

<th:block th:switch="${mapResult.bidType}">
    <th:block th:case="'1'">
        <head th:replace="common/include-header :: header (${bidProjectTypeMap[mapResult.bidProjectType]}+'公告變更')"/>
    </th:block>
    <th:block th:case="'2'">
        <head th:replace="common/include-header :: header ('投標邀請變更')"/>
    </th:block>
    <th:block th:case="*">
        <head th:replace="common/include-header :: header (${bidProjectTypeMap[mapResult.bidProjectType]}+'公告變更')"/>
    </th:block>
</th:block>

判斷物件屬性是否存在

<p class="project-name" th:if="${#maps.containsKey(mapResult, 'bidType')}">
<span th:text="${mapResult.bidType}"></span>
</p>
另
// 判斷物件的屬性是否存在
var userMobile = [[${user?.mobile}]];

頁面定義變更 th:with

<html xmlns:th="http://www.thymeleaf.org" th:with="COMPANY_NAME='聯成化學科技股份有限公司'">

相關文章