Spring boot integrates mybatis

Reference link:

http://412887952-qq-com.iteye.com/blog/2303121

http://blog.didispace.com/springbootmybatis/

http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/

 

maven dependencies:

       <dependency>

   <groupId>mysql</groupId>

   <artifactId>mysql-connector-java</artifactId>

</dependency>

 

<dependency>

<groupId>org.mybatis.spring.boot</groupId>

<artifactId>mybatis-spring-boot-starter</artifactId>

<version>1.1.1</version>

</dependency>

 

<dependency>

        <groupId>com.github.pagehelper</groupId>

        <artifactId>pagehelper</artifactId>

        <version>4.1.6</version>

    </dependency>

 

 

 

In addition, spring boot needs to use the @Mapper annotation to read mapper, and the @Responsity annotation is not scanned.

Advanced scanning

MyBatis-Boot-Starter will search, by default, for mappers marked with the @Mapper annotation.

You may want to specify a custom annotation or a marker interface for scanning. If so, you must use the @MapperScan annotation. See more about it in the MyBatis-Spring reference page.

MyBatis-Boot-Starter will not start the scanning process if it finds at least one MapperFactoryBean in the Spring's context so if you want to stop the scanning at all you should register your mappers explicitly with @Bean methods.

 

 

mybatis paging can use PageHelper

 

If the query is List, then use the @Results annotation method of mybatis

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326585498&siteId=291194637