使用.xml配置的方式
整合步骤:
1、创建Mapper接口文件,在主程序添加包扫描
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a718f064029c62464235d2c0eb25bef8.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0d6ac2b4b949e7d7f8c0e5868a7645c0.png)
2、创建XML映射文件:编写对应的SQL语句
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9115dafe2c5e0722d729b32e5617ba75.png)
3、在全局文件中配置XML映射文件路径
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/26c064899e7277c0fa9a7988ba0a4a93.png)
4、在.yml中配置数据库
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource #使用druid连接池
url: jdbc:mysql://localhost:3306/school?characterEncoding=utf8
password: root
username: root
driver-class-name: com.mysql.jdbc.Driver
5、编写测试方法进行接口方法测试及整合测试
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e56af553019dbc3705564e069a8463a6.png)
运行结果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/815ad0e1115a2ea9f8d0716c66404896.png)
使用注解方式
整合步骤:
1.创建Mapper接口文件:@Mapper
2.在接口里的方法添加注解
使用方式:
@select、update、delete、insert(sql语句)
接口方法
例子:
@Select("select * from t_comment where id=#{id}")
public Comment findCommentById(Integer id);
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/138bab33c704054439aa9e4205fa1cf2.png)