简介
springboot集成mybaits时,有mybatis官方提供的mybatis-spring-boot-starter,但mapper不可通用,开发工作量大,
因此使用mapper-spring-boot-starter的通用mapper。
通用Mapper都可以极大的方便开发人员。
可以随意的按照自己的需要选择通用方法,还可以很方便的开发自己的通用方法。
极其方便的使用MyBatis单表的增删改查。
支持单表操作,不支持通用的多表联合查询。
pom
1 | <dependency> |
配置
- 数据源配置
参考druid-spring-boot-starter配置即可
- mybatis配置
config-location与configuration只可配置一项
1 | config-location: classpath:mybatis-config.xml |
- mapper配置
详见wiki
mappers配置项注意
如果只使用通用mapper,可以不配置mappers,如果使用了MysqlMapper等其他mapper,而且自己定义了BaseMapper,要设置mappers。(一般BaseMapper继承Mapper和其他mapper,比如MysqlMapper)
1 | mapper: |
开撸
关于@MapperScan
包名必填,并且mappers配置的类不能在包下
对象关系映射
- 主键 @Id
- 列 @Column @ColumnType