46-Thymeleaf数据回显

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')"

posted on 2020-07-05 21:55  liqiangbk  阅读(2096)  评论(0编辑  收藏  举报

导航