实践MyBatis通用mapper

通用mapper

1
2
3
4
5
<dependency>
	<groupId>tk.mybatis</groupId>
	<artifactId>mapper</artifactId>
	<version>3.5.0</version>
</dependency>

mapper spring boot starter

1
2
3
4
5
<dependency>
	<groupId>tk.mybatis</groupId>
	<artifactId>mapper-spring-boot-starter</artifactId>
	<version>1.2.1</version>
</dependency>

基于mybatis-spring-boot-starter,新版本Mybatis Mapper不再基于mybatis-spring-boot-starter

提供自动配置MapperAutoConfiguration

mapper for MyBatis Generator

为了配合通用mapper,对MyBatis Generator做了一些自定义的扩展,主要包括:

  • MapperCommentGenerator

自定义注释生成器

  • useMapperCommentGenerator

<context>增加<property>:useMapperCommentGenerator,默认值是true,表示使用自定义注释生成器MapperCommentGenerator

  • MapperPlugin
1
2
3
<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
	<property name="mappers" value="tk.mybatis.mapper.common.Mapper"/>
</plugin>
属性 描述 备注
caseSensitive 默认值:false  
forceAnnotation 是否强制生成注解(@Table,@Column),默认值:false 也用于注释生成器,依赖<context><property>之useMapperCommentGenerator
beginningDelimiter 默认值:空串 同上,作用于@Table和@Column
endingDelimiter 默认值:空串 同上,作用于@Table和@Column
schema 数据库schema,默认值:null 表名前缀,作用于@Table