MyBatis写一个接口,需要映射到配置文件的sql语句,mybatisplus省去了繁琐的操作
需要Lombok插件支持,只需要安装一下就可以了
参考链接比较全面
学习MyBatis-Plus3这一篇就够了_轻松的小希的博客-CSDN博客_mybatisplus3
前提:项目配置
Spring Boot的依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.0</version>
</dependency>
Spring MVC的依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.4.0</version>
</dependency>
配置 MapperScan 注解
@SpringBootApplication
@MapperScan("com.caochenlei.mpdemo.mapper") // 包扫描
public class MpDemoApplication {
public static void main(String[] args) {
SpringApplication.run(MpDemoApplication.class, args);
}
}
配置文件 application.properties 配置数据库和mybatisplus的相关东西
#mysql
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mp?useUnicode=true&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=123456
#mybatis-plus
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl