templates
使用这个包下的文件 需要导入jar 包 并且在页面接收templates包下文件的数据需要添加约束
jar包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
页面依赖
<html lang="en" xmlns:th="http://www.thymeleaf.org">
templates的简单语法
<!--文本-->
<div th:text="${msg}"></div>
<!--接收后台传输的数据-->
<div> [[ ${msg} ]]</div>
<!--不转义-->
<div th:utext="${msg2}"></div>
<!--遍历集合-->
<div th:each="user : ${msglist} " th:text="${user}"></div>
<!--遍历集合的第二种方式-->
<div th:each="user : ${msglist} ">[[ ${user} ]]</div>
简单的增删改查
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table>
<!-- 表头-->
<thead>
<tr>
<td>id</td>
<td>账号</td>
<td>密码</td>
</thead>
<!-- 后台返回页面数据 数据名叫做 list 是一个list集合 里面存放的是user-->
<tr th:each="user,index:${list}">
<td th:text="${index.index}"></td>
<td th:text="${user.getId()}"></td>
<td th:text="${user.getName()}"></td>
<td th:text="${user.getPassword()}"></td>
<td><a th:href="@{'/login/remove/'+${user.getId()}}">删除</a></td>
</tr>
</table>
<hr/>
<hr/>
<hr/>
<h1>添加用户</h1>
<form th:action="@{/login/add}" method="post">
id:<input type="text" name="id" />
用户名:<input type="text" name="name" />
密码:<input type="text" name="password" />
<input type="submit" value="提交" />
</form>
<hr/>
<hr/>
<hr/>
<h1>修改用户</h1>
<form th:action="@{/login/updata}" method="post">
id:<input type="text" name="id" />
用户名:<input type="text" name="name" />
密码:<input type="text" name="password" />
<input type="submit" value="提交" />
</form>
</body>
</html>