SpringBoot整合第三方技术

1|0整合JUnit

名称:@SpringBootTest
类型:测试类注解
位置:测试类定义上方
作用:设置JUnit加载的SpringBoot启动类
范例:

@SpringBootTest(classes = Springboot07JunitApplication.class)class Springboot07JunitApplicationTests {}

注:

classes:设置SpringBoot启动类

如果测试类在SpringBoot启动类的包或子包中,可以省略启动类的设置,也就是省略classes的设定

 

 

 

2|0整合Mybatis

 

 

 

 

 

 

3|0yml设置数据源参数

 

 

 注意

SpringBoot版本低于2.4.3(不含),Mysql驱动版本大于8.0时,需要在url连接串中配置时区

jdbc:mysql://localhost:3306/ssm_db?serverTimezone=UTC

或在MySQL数据库端配置时区解决此问题

 

4|0Dao inferface定义数据层接口与映射配置

@Mapper的作用是什么?

运行中肯定需要对象运行interface中的方法才行,

那对象怎么来?

Spring的操作中需要ComponentScan来告诉这个类需要自动代理

而在SpringBoot中@Mapper就告诉SpringBoot这个类要做自动代理,简化了开发

@Mapperpublic interface UserDao {   @Select("select * from user")  public List<User> getAll();}

 

5|0测试类中注入dao接口,测试功能

复制代码
@SpringBootTest class Springboot08MybatisApplicationTests { @Autowired private BookDao bookDao; @Test public void testGetById() { Book book = bookDao.getById(1); System.out.println(book); } }
复制代码

 

 

代码来源:itheima


__EOF__

本文作者qintee
本文链接https://www.cnblogs.com/qintee/p/17247950.html
关于博主
版权声明
声援博主
posted @   qintee  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示