Thymeleaf數據回顯
input回填
<div class="form-group">
<label class="col-sm-1 control-label">用戶名:</label>
<div class="col-sm-3">
<input id="username" name="username" th:value="${user.username}" class="form-control" type="text">
</div>
</div>
單選回填
<div class="form-group">
<label class="col-sm-1 col-sm-offset-2 control-label">性別 :</label>
<div class="col-sm-3">
<label class="radio-inline" th:each="sex:${sexList}">
<input type="radio" id="sex" name="sex" th:value="${sex.value}" th:text="${sex.name}" th:attr="checked=${user.sex == sex.value?true:false}" />
</label>
</div>
</div>
時間框回填
<div class="form-group">
<label class="col-sm-1 control-label">出生日期:</label>
<div class="col-sm-3">
<input type="text" class="laydate-icon layer-date form-control" id="birthday" name="birthday" th:value="${user.birthday}==null?null:${#dates.format(user.birthday,'yyyy-MM-dd')}" οnclick="laydate({istime: true, format: 'YYYY-MM-DD'})" style="background-color: #fff;" readonly="readonly" />
</div>
</div>
下拉回填
<div class="form-group">
<label class="col-sm-1 col-sm-offset-2 control-label">職業:</label>
<div class="col-sm-3">
<select data-placeholder="--選擇類別--" name="profession" id="profession" class="form-control chosen-select" tabindex="2" required>
<option value="">--選擇類別--</option>
<option th:selected="${user.profession eq profession.value}" th:each="profession:${professionTypeList}" th:value="${profession.value}" th:text="${profession.name}"></option>
</select>
</div>
</div>
textarea數據回顯
thymeleaf的textarea數據回顯用th:text,th:value不能回顯
集合的非空判斷
th:if="${not #lists.isEmpty(自定義集合)}"
字符串拼接
<span th:text="|Welcome to HeBei, ${user.name}!|">
//這實際上相當於:
<span th:text="'Welcome to HeBei, ' + ${user.name} + '!'">
//文字替換可以與其他類型的表達相結合:
<span th:text="${onevar} + ' ' + |${twovar}, ${threevar}|">
小數(四舍五入)
//顯示1.24
th:text="${#numbers.formatDecimal(1.235, 1, 2)}"
a標簽-超鏈接
<a th:href="@{/user/doUpdate/(id=${companyUser.id},username=${user.username})}">view</a>
<a th:href="@{/user/{user.id}/getUserByUserName>view</a>
三元運算符判斷
th:text="'Execution mode is ' + ( ('0'!='0')? 'Development' : 'Production')"