一、Mybatis-Plus 介绍
减少程序员编写简单的CURD操作
二、Mybatis-Plus 使用
1、maven 加载依赖
mybatis-plus-boot的依赖:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
其他依赖:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
2、使用配置
(1) application.properties:
#spring连接mysql
#连接配置
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis-plus-component?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
#mybatis-plus 输出日志
#日志输出
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
(2) DAO层创建UserMapper.java类:
@Component
public interface UserMapper extends BaseMapper<UserEntity> {
}
(3) 启动类MybatisPlusApplication:
@SpringBootApplication
@MapperScan("com.component.mybatisplus.dao")
public class MybatisPlusApplication {
public static void main(String[] args) {
SpringApplication.run(MybatisPlusApplication.class, args);
}
}