SpringBoot整合jsp、thymeleaf、mybatis

                                                           


 

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==

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值