Mapper-Spring-Boot-Starter 帮助你集成通用 Mapper 到 Spring Boot。
Mapper-Spring-Boot-Starter will help you use Mapper with Spring Boot.
在 pom.xml 中添加如下依赖:
Add the following dependency to your pom.xml:
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
tk.mybatis.spring.mapper.SpringBootBindUtil
,使用原生方式兼容 Spring Boot 1.x 和 2.x 版本,已经不存在 relax 值问题,以前的配置不需要修改即可使用。@MapperScan
注解,请使用 tk.mybatis.spring.annotation.MapperScan
注解。为了增强兼容性,MapperAutoConfiguration
增加 @AutoConfigureBefore(name = "org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration")
即使依赖中存在 MyBatis 的 starter,Mapper 也可以优先使用自动配置,MyBatis后续就不会触发生成 @Bean
支持简单的 relax 绑定,例如 not-empty 会转换为 notEmpty 使用,兼容 spring boot 配置方式
@MapperScan
请选择 tk 开头的 tk.mybatis.spring.annotation.MapperScan
一般情况下,你不需要做任何配置。
Normally, you don't need to do any configuration.
如果需要配置,可以使用如下方式进行配置:
You can config PageHelper as the following:
application.properties:
mapper.propertyName=propertyValue
示例:
mapper.mappers[0]=tk.mybatis.sample.mapper.BaseMapper
mapper.mappers[1]=tk.mybatis.mapper.common.Mapper
默认情况下,没有 mappers 配置时,会自动注册 tk.mybatis.mapper.common.Mapper
因为通用 Mapper 是固定的属性,所以接收参数使用的对象,按照 Spring Boot 配置规则,大写字母都变了带横线的小写字母。针对如 IDENTITY(对应i-d-e-n-t-i-t-y)提供了全小写的 identity 配置,如果 IDE 能自动提示,看自动提示即可。
IDE 应该可以自动提示:
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。