使用通用mapper可以不再写基础的增删改查语句,让mapper.xml只专注复杂的SQL不受大量的基础增删改查语句干扰
pom.xml引入依赖
<!-- Common Mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>RELEASE</version>
</dependency>
配置文件application.yml,BaseMapper
mybatis:
type-aliases-package: com.sb.example.*.model
mapper-locations: classpath:mapper/*.xml
mappers: com.sb.example.common.util.BaseMapper
not-empty: false
identity: MYSQL
package com.sb.example.common.util;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;
@Component
public interface BaseMapper<T> extends Mapper<T>, MySqlMapper<T> {
}