1. Introducing Jar to Pom.xml
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>3.4.0</version>
</dependency>
<!--Https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper--
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.0</version>
</dependency>
2, Configuration Mapper
Create Application-bean.xml, file contents as follows
<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans.xsd ">
<!--inject the bean that spring boot cannot scan. -
<bean class= "Tk.mybatis.spring.mapper.MapperScannerConfigurer" >
<property name= "Basepackage" value= "study.boot.config. Mymapper "/>
<property name= "Properties" >
<value>
Mappers=tk.mybatis.mapper.common.mapper
</value>
</property>
</bean>
</beans>
3. Create a configuration class
Import org.springframework.context.annotation.Configuration;
Import Org.springframework.context.annotation.ImportResource;
@Configuration
@ImportResource (value={"Classpath:application-bean.xml"})
public class Configclass {
}
Import java.util.Properties;
Import Org.slf4j.Logger;
Import Org.slf4j.LoggerFactory;
Import Org.springframework.context.annotation.Bean;
Import org.springframework.context.annotation.Configuration;
Import Com.github.pagehelper.PageHelper;
@Configuration
public class Mybatisconfiguration {
private static final Logger Logger = Loggerfactory.getlogger (Mybatisconfiguration.class);
@Bean
Public Pagehelper Pagehelper () {
Logger.info ("Register MyBatis page plug-in Pagehelper");
Pagehelper pagehelper = new Pagehelper ();
Properties P = new properties ();
P.setproperty ("Offsetaspagenum", "true");
P.setproperty ("Rowboundswithcount", "true");
P.setproperty ("reasonable", "true");
Pagehelper.setproperties (P);
return pagehelper;
}
}
Import Tk.mybatis.mapper.common.Mapper;
Import Tk.mybatis.mapper.common.MySqlMapper;
Public interface mymapper<t> extends Mapper<t>, mysqlmapper<t> {
}
4. Practical Application
MyBatis's mapper Inherits General Mapper
@Mapper
Public interface Citymapper extends mymapper<city>{
}
Direct use
@RestController
@RequestMapping ("/Boot")
public class HelloWorld {
@Autowired
Citymapper Citymapper;
@RequestMapping ("/hello")
Public list<city> Greeting () {
Pagehelper.startpage (1, 5);
return Citymapper.selectall ();
}
}
Springboot MyBatis Integrated Mapper and Pagehelper