SpringbootTemplatesApplication 是springboot的启动类
该类位置必须同entity、mapper等包的级别相同,因为它只能向下扫描 意思就是 只能扫描它子包及同等级包
application.yml 是springboot的配置文件 同application.properties相同 二者都可以 由于yml文件的好处 所以推荐使用yml文件
无论是yml文件、还是properties文件 都必须以application名开头
#端口更改
server:
port: 8080
#设置模板 及 前后缀
spring:
# mvc:
# view:
# prefix:
# suffix:
thymeleaf:
cache: false
mode: LEGACYHTML5
encoding: utf-8
#数据源
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/work1
username: root
password: admin
driver-class-name: com.mysql.jdbc.Driver
#设置mybatis
mybatis:
mapper-locations: classpath:com/qust/mapper/*Mapper.xml
type-aliases-package: com.qust.entity
在mapper接口或者dao接口中添加 @Mapper
或者在 SpringbootTemplatesApplication 启动文件中添加@MapperScan("com.qust.mapper.UserMapper")
二者加一即可
templates 结合html文件配置
在html中添加
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table>
<tr>
<th>UID</th>
<th>UNAME</th>
<th>UPWD</th>
<th>USEX</th>
<th>操作</th>
</tr>
<tbody>
<tr th:each="u:${userList}">
<td th:text="${u.uid}">0</td>
<td th:text="${u.uname}">0</td>
<td th:text="${u.upwd}">0</td>
<td th:text="${u.usex}">0</td>
<td>
<!-- 路径传参-->
<a th:href="@{findOne/{uid}(uid=${u.uid})}">修改</a>
<!-- 问号传参-->
<a th:href="@{deleteUser(uid=${u.uid})}">删除</a>
<!-- 路径传参-->
<a th:href="@{'/findOne/' + ${u.uid}}">update</a>
</td>
</tr>
</tbody>
</table>
</body>
</html>
修改界面传值
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>更新页面</title>
</head>
<body>
<form action="/dpdate" method="post" th:object="${user}">
<input type="text" name="uid" th:value="*{uid}"/><br>
Uname:<input type="text" name="uname" th:value="*{uname}"/><br>
Upwd:<input type="password" name="upwd" th:value="*{upwd}"/><br>
Usex:<input type="text" name="usex" th:value="*{usex}"/><br>
<input type="submit" value="提交">
</form>
</body>
</html>
![点击并拖拽以移动 wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==](https://img-blog.csdnimg.cn/2022010614264641849.gif)