SpringBoot整合MybatisPlus(powernode CD2207)(内含教学视频+源代码)
教学视频+源代码下载链接地址:
https://mp.csdn.net/mp_download/manage/download/UpDetailed
目录
- SpringBoot整合MybatisPlus(powernode CD2207)(内含教学视频+源代码)
- `教学视频+源代码下载链接地址:`[https://mp.csdn.net/mp_download/manage/download/UpDetailed](https://mp.csdn.net/mp_download/manage/download/UpDetailed)
- 零、步骤
- 一、创建一个SpringBoot项目
- 二、修改pom.xml中SpringBoot的版本,并导入依赖
- 2.1 修改pom.xml中SpringBoot的版本为2.7.6
- 2.2 导入mybatis-plus的依赖
- 2.3 导入druid的依赖
- 三、使用MybatisX插件逆向生成代码
- 四、application.yml
- 五、启动类加上@MapperScan注解
- 六、测试类和测试结果
整合mybatis-plus
零、步骤
1.导包: 导入Mybatispuls的启动器 、druid、(mysql驱动)
2.配置数据源: 没有区别
3.配置mybatis核心配置:
前缀为mybatisplus
前缀后的内容
4.扫描Mapper包:没有区别
一、创建一个SpringBoot项目
二、修改pom.xml中SpringBoot的版本,并导入依赖
2.1 修改pom.xml中SpringBoot的版本为2.7.6
2.2 导入mybatis-plus的依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
2.3 导入druid的依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.9</version>
</dependency>
三、使用MybatisX插件逆向生成代码
上面点击Test Connection如果报错,报错信息为下面这个的话
Failed [08S01] Communications link failure The last packet successfully received from the server was 89 milliseconds ago. The last packet sent successfully to the server was 81 milliseconds ago. No appropriate protocol (protocol is disabled or cipher suites are inappropriate).
则我们点击Advanced,将useSSL修改为false。
四、application.yml
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:13306/ssm_power_edu?characterEncoding=utf-8&serverTimezone=UTC
driver-class-name: com.mysql.jdbc.Driver
username: root
password: root
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: classpath:mappper/*.xml
五、启动类加上@MapperScan注解
package com.bjpowernode.springboot32mybatisplus;
import com.bjpowernode.springboot32mybatisplus.service.UserService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@MapperScan("com.bjpowernode.springboot32mybatisplus.mapper")
@SpringBootApplication
public class Springboot32MybatisplusApplication {
public static void main(String[] args) {
SpringApplication.run(Springboot32MybatisplusApplication.class, args);
}
}
六、测试类和测试结果
package com.bjpowernode.springboot32mybatisplus;
import com.bjpowernode.springboot32mybatisplus.domain.User;
import com.bjpowernode.springboot32mybatisplus.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
class Springboot32MybatisplusApplicationTests {
@Autowired
private UserService userService;
@Test
void contextLoads() {
List<User> userList = userService.list();
userList.forEach(System.out::println);
}
}