mybatis 实现分页功能, mybatis plus 实现分页功能

2023-12-18 12:37:52

1 mybatis 实现分页功能

    @ApiModelProperty(value = "开始页")
    private Integer page = 1;
    @ApiModelProperty(value = "每页数据个数")
    private Integer rows = 10;

以上是前端传过来的数据

    @Override
    public Map<String,Object> getFbList(EleInput EleInput) {
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        Integer page = EleInput.getPage();
        Integer rows = EleInput.getRows();
        EleInput.setPage((page - 1)*rows);
        List<Ele> fbList = EleMapper.getFbList(EleInput);
        int fbListCount = EleMapper.getFbListCount(EleInput);
        stringObjectHashMap.put("list",fbList);
        stringObjectHashMap.put("count",fbListCount);
        return stringObjectHashMap;
    }

xml 里面写法

在这里插入图片描述

2 mybatis plus 实现分页功能

@Configuration
//@MapperScan("com.example.demo.mapper")
public class MybatisPlusConfig {

    /**
     * 新增分页拦截器,并设置数据库类型为mysql
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

}

业务层

        //分页参数
        Page<SchoolStudent> rowPage = new Page(page, pageSize);

        //queryWrapper组装查询where条件
        LambdaQueryWrapper<SchoolStudent> queryWrapper = new LambdaQueryWrapper<>();
        rowPage = this.baseMapper.selectPage(rowPage, queryWrapper);
        return rowPage;

文章来源:https://blog.csdn.net/python113/article/details/135055307
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。