spring boot+thymeleaf+mybatis通过url传值实现前后端数据交互,操作mysql数据库

这篇博客介绍了如何在Spring Boot项目中使用Thymeleaf替换SSM框架中的JSP,实现前后端数据交互。通过URL传值,结合Mybatis的注解操作MySQL数据库,包括查找、更新等操作。文章强调了Thymeleaf与SSM框架中传参的不同,以及在Thymeleaf中避免使用SSM的写法以防止参数解析错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 环境准备
  2. controller层 html文件 jsp文件部分代码

写在前面:

本贴记录我在将ssm项目改为springboot+thymeleaf过程中遇到的问题,数据访问层使用mapper(接口),使用@Insert、@Update、@Delete、@Select注解操作数据库,仅学习记录非教程。

作业要求:新建一个Spring Boot的项目,将作业2(SSM框架实现)中的实体类、数据访问层和Controller的代码复制到本项目中,然后将作业2中的JSP页面改成用Thymeleaf来实现。

1.1.idea新建springboot项目,添加依赖包

maven添加依赖

<dependency>
   <groupId>org.mybatis.spring.boot</groupId>
   <artifactId>mybatis-spring-boot-starter</artifactId>
   version>2.2.2</version>
</dependency>

1.2 编写配置文件application.properties

spring.thymeleaf.cache=false
spring.thymeleaf.encoding=utf-8
spring-thymeleaf.mode=HTML
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.messages.basename=i18n.login
#文件上传配置
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=50MB
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/javawebwork?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.show-sql=true
spring.data.redis.host=localhost
spring.data.redis.port=6379
spring.data.redis.password=root
spring.cache.redis.time-to-live=60000
#整合mybatis
#给pojo实体类起别名
mybatis.type-aliases-package
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值