36 SpringBoot与通用Mapper和分页插件整合

版权声明:看什么?6,你和我,走一波! https://blog.csdn.net/qq_31323797/article/details/85337622

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>

<!-- 通用Mapper -->
<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批量扫描所有的Mapper接口,此时CartMapper上的mapper就可以注释
@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());
}

猜你喜欢

转载自blog.csdn.net/qq_31323797/article/details/85337622
36