SpringBoot3 学习笔记 (整合Mybatis-plus)
1、引入依赖,网址:https://mvnrepository.com/artifact/com.baomidou
这里最新版本为3.5.3.2,点击进去
2、在pom.xml中添加依赖,并确认依赖中已经有了mysql-connector-j的依赖
<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.3.2</version> </dependency>
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>8.1.0</version> </dependency>
3、在application.yml文件中配置数据源
spring: datasource: url: jdbc:mysql://localhost:3306/boottest?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf8 //为mysql8 username: root password: 123456
4、编写测试类
@Resource //不要用@Autowired DataSource dataSource; @Test void contextLoads() throws Exception { System.out.println(dataSource.getClass()); System.out.println(dataSource.getConnection()); }
输出结果为