Spring Boot分页

第一步:定义方法

@PostMapping("list")
    public Object list(@RequestBody PageParam pageParam) {
        //当前页码
        int current = (int)pageParam.getPageNum();
        //每页条数
        int size = (int)pageParam.getPageSize();

        //构建 分页构造器
        IPage page = new Page(current, size);
        //构建 条件构造器

        QueryWrapper wrapper = new QueryWrapper<>();
        userMapper.selectPage(page, wrapper);

        List records = page.getRecords();//当前页数据
        long total = page.getTotal();//总条数
        long pages = page.getPages();//总页数

        records.forEach(System.out::println);

        System.out.println("当前数据总共有:"+total);
        System.out.println("共"+pages+"页");
        System.out.println("当前页数据:"+records);

        return Result.suc(records, total);
    }

第二步:定义UserMapper.java

package com.example.demo12.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo12.entity.User;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper {
    List listAll();
}

第三步:UserMapper.xml




    
    
    
    

你可能感兴趣的:(springboot)