Spring Boot分页方法定义示例
作者:小拼拼
这篇文章主要为大家介绍了Spring Boot 分页方法定义,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
第一步:定义方法
@PostMapping("list") public Object list(@RequestBody PageParam pageParam) { //当前页码 int current = (int)pageParam.getPageNum(); //每页条数 int size = (int)pageParam.getPageSize(); //构建 分页构造器 IPage<User> page = new Page(current, size); //构建 条件构造器 QueryWrapper<User> wrapper = new QueryWrapper<>(); userMapper.selectPage(page, wrapper); List<User> 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<User> { List<User> listAll(); }
第三步:UserMapper.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.example.demo12.mapper.UserMapper"> <select id = "listAll" resultType="com.example.demo12.entity.User"> select * from user </select> <select id = "userCount" resultType="java.lang.Integer"> select count(1) from user </select> <select id = "listTest" resultType="com.example.demo12.entity.User"> select * from user </select> <select id = "testUserCount" resultType="java.lang.Integer"> select count(1) from user </select> </mapper>
以上就是Spring Boot 分页方法定义的详细内容,更多关于Spring Boot 分页的资料请关注脚本之家其它相关文章!