1 引入依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.0.2</version>
</dependency>
2 配置
#通用Mapper
mapper.mappers=com.gp6.springboot31.utils.MapperUtil
mapper.identity=MYSQL
#分页插件
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
3 扫描更改
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import tk.mybatis.spring.annotation.MapperScan;
@MapperScan(value = "com.gp6.springboot31.mapper")
@SpringBootApplication
public class Springboot31Application {
public static void main(String[] args) {
SpringApplication.run(Springboot31Application.class, args);
}
}
4 自定Mapper接口
package com.gp6.springboot31.utils;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;
public interface MapperUtil<T> extends Mapper<T>, MySqlMapper<T> {
}
5 Mapper继承MapperUtil
public interface ItemParamTemplateMapper extends MapperUtil<ItemParamTemplate> {
}
6 测试
@GetMapping("/itemParamTemplate")
public PageInfo<ItemParamTemplate> selectItemParamTemplateList() {
PageHelper.startPage(1,5);
return new PageInfo<>(itemParamTemplateMapper.selectAll());
}