mybatis-spring-boot-starter
How to use it
- first add dependency to your project
<dependency>
<groupId>xyz.luomu32</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>LATEST</version>
</dependency>
- write xml mapper file and add to ‘mapper’ directory under
src/main/resources
- write java data access class and with @Mapper annotation
- enjoy it
Configuration
XML mapper file
by the default,the starter will try to load xml file at 'mapper' directory under src/main/resource
.you can also change it with application.properties or application.yml.like this:
mybatis:
mapper-locations: classpath:mapper/*.xml
or
mybatis:
mapper-locations:
- classpath:mapper/*.xml
- classpath:User.xml
Java Mapper
by the default,the starter will try to scan Java Mapper with @Mapper annotation under your base project package.you can also dem the package,and the @Mapper annotation will not necessary.
mybatis:
mapper-base-package: com.xxx.xxx.dao
Plugin
mybatis:
interceptors: xyz.luomu32.mybatis.plugin.OptimisticLockInterceptor
or just add to Spring container with @Compent or @Bean.the starter will get bean which implement org.apache.ibatis.plugin.Interceptor
from Spring container,and register it to Mybatis.