Thymeleaf获取后台的传值实现一套增删改查(已验证)
1.现实展示list集合:
效果:
spring boot 的代码:
//标题 展示
@RequestMapping(value="/titleIndex")
public String agentMgddStzzringrIndex(HttpSession session){
List<Titles> titles = userService.findTitles();
String i="";
if(titles ==null) {
i="暂无数据";
session.setAttribute("i",i);
}else {
session.setAttribute("i",i);
session.setAttribute("titles",titles);
}
return "titleIndex";
}
Thymeleaf模板html代码:
<!-- 循环 多个循环 -->
<tr th:each="c, State : ${session.titles}">
<td th:text="${c.id}"></td>
<td th:text="${c.title}"></td>
<td>
<button class="change">修改</button>
<button class="delete">删除</button>
<button class="details">详情</button>
</td>
</tr>
2.展示单个数据:
效果:
spring boot 的代码:(这里是要跳转到这里的路径)
session.setAttribute("total", total);
Thymeleaf模板html代码:
<div class="create">
<h2>人数:<span th:text="${session.total}"></span></h2>
</div>
3.a标签跳转带参数:
Thymeleaf模板html代码:
```java
<div class="add">
<a href="/userAdd" th:href="@{/userAdd(id=${session.id})}"><button>添加用户</button></a>
</div>
4.隐藏一个参数:
Thymeleaf模板html代码:
<input name="id" id="id" type="hidden" th:value="${session.id}">
5,if判断不等于0,!=
Thymeleaf模板html代码:
<div th:if="${session.total ne 0}"></div>
6.展示第条数据:
Thymeleaf模板html代码:
<td th:text="${session.customers.name}"></td>
<td th:text="${session.customers.passWord}"></td>
</table>