Spring Boot分頁方法定義示例
第一步:定義方法
@PostMapping("list")
public Object list(@RequestBody PageParam pageParam) {
//當(dāng)前頁碼
int current = (int)pageParam.getPageNum();
//每頁條數(shù)
int size = (int)pageParam.getPageSize();
//構(gòu)建 分頁構(gòu)造器
IPage<User> page = new Page(current, size);
//構(gòu)建 條件構(gòu)造器
QueryWrapper<User> wrapper = new QueryWrapper<>();
userMapper.selectPage(page, wrapper);
List<User> records = page.getRecords();//當(dāng)前頁數(shù)據(jù)
long total = page.getTotal();//總條數(shù)
long pages = page.getPages();//總頁數(shù)
records.forEach(System.out::println);
System.out.println("當(dāng)前數(shù)據(jù)總共有:"+total);
System.out.println("共"+pages+"頁");
System.out.println("當(dāng)前頁數(shù)據(jù):"+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 分頁方法定義的詳細(xì)內(nèi)容,更多關(guān)于Spring Boot 分頁的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
SpringBoot實(shí)現(xiàn)自定義線程池的方法
這篇文章主要介紹了SpringBoot中的自定義線程池解析,實(shí)現(xiàn)自定義線程池重寫spring默認(rèn)線程池的方式使用的時(shí)候,只需要加@Async注解就可以,不用去聲明線程池類,需要的朋友可以參考下2023-11-11
Java視頻格式轉(zhuǎn)化的實(shí)現(xiàn)方法
這篇文章主要為大家詳細(xì)介紹了Java視頻格式轉(zhuǎn)化的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02
Java HashMap 如何正確遍歷并刪除元素的方法小結(jié)
這篇文章主要介紹了Java HashMap 如何正確遍歷并刪除元素的方法小結(jié),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
Java Redis分布式鎖的正確實(shí)現(xiàn)方式詳解
這篇文章主要介紹了Java Redis分布式鎖的正確實(shí)現(xiàn)方式詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09
基于SSM實(shí)現(xiàn)學(xué)生管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了基于SSM實(shí)現(xiàn)學(xué)生管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-12-12
Java中final關(guān)鍵字的使用與注意總結(jié)
這篇文章主要給大家介紹了關(guān)于Java中final關(guān)鍵字的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者使用Java具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08
Java Web Fragment在項(xiàng)目中使用方法詳解
這篇文章主要介紹了Web Fragment在項(xiàng)目中使用方法詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-02-02
Java?ArrayList遍歷foreach與iterator時(shí)remove的區(qū)別
這篇文章主要介紹了Java?ArrayList遍歷foreach與iterator時(shí)remove的區(qū)別,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下2022-07-07

