Spring Boot通用mapper整合的方法及步骤
**通用mapper整合(作用是将单表的增删改查操作省去)
1、导入pom依赖
1 2 3 4 5 6 7 8 9 10 11 12
| <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>2.0.2</version> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </exclusion> </exclusions> </dependency>
|
2、配置mapper ,继承通用mapper
1 2 3
| import tk.mybatis.mapper.common.Mapper;
public interface UserMapper extends Mapper<UmsMember> {
|
3、配置通用mapper主键和主键返回策略
1
| @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
4、配置启动类扫描MapperScan,使用通用mapper的MapperScan
1
| import tk.mybatis.spring.annotation.MapperScan;
|
>>如果想查看执行的sql语句,需要修改日志级别为debug
1 2
| #日志级别 logging.level.root=debug
|