Thymeleaf在springboot中的使用

依赖

<!--thymeleaf-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

html页面添加头文件名

<html lang="en"  xmlns:th="http://www.thymeleaf.org">


thymeleaf 标签实现 if else 的写法

thymeleaf 要用 switch 和 case 实现 if else:

<td th:switch = "${users.getStatus()}">
    <div th:case="1" th:text = "正常" ></div>
    <div th:case="0" th:text = "禁用" ></div>
</td>


th:onclick点击传递参数

<a class="btn btn-xs btn-default" th:onclick="|delete1(${users.getId()})|"  title="删除" data-toggle="tooltip">


function delete1(diarycontent){
alert(diarycontent);
}


thymeleaf : input/select/radio回显

thymeleaf中不用自己去写checked="checked" selected="selected"这种代码,他自己会选。

input

<input type="text" class="form-control1" id="name" name="name" th:value="${user.name}">

select

<label  class="col-sm-2 control-label">类别</label>
<div class="col-sm-8">
    <select  name="cId" id="cId" class="form-control1" >
        <option value="1" th:field="*{book.cId}">目录1</option>
        <option value="2" th:field="*{book.cId}">目录2</option>
        <option value="3" th:field="*{book.cId}">目录3</option>
        <option value="4" th:field="*{book.cId}">目录4</option>
    </select>
</div>

radio(*{回显数据})

    <label for="isBoy" class="col-sm-2 control-label">是否男生</label>
    <div id="isBoy" class="col-sm-8">
        <div class="radio-inline">
            <label><input name="isBoy" type="radio" value="1"  th:field="*{book.isBoy}"/> 否</label>
        </div>
        <div class="radio-inline">
            <label><input name="isBoy" type="radio" value="0"  th:field="*{book.isBoy}"/> 是</label>
        </div>
    </div>

thymeleaf设置表格中字符串长度

<td th:text="${#strings.abbreviate(feedBacks.getContent(),28)}" style="width: 400px;"></td>

分类: 技术 标签: 暂无标签

评论

暂无评论数据

暂无评论数据

目录