Spring Boot分頁方法定義示例
更新時間:2023年09月22日 09:35:09 作者:小拼拼
這篇文章主要為大家介紹了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 分頁方法定義的詳細內(nèi)容,更多關(guān)于Spring Boot 分頁的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Java HashMap 如何正確遍歷并刪除元素的方法小結(jié)
這篇文章主要介紹了Java HashMap 如何正確遍歷并刪除元素的方法小結(jié),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
基于SSM實現(xiàn)學(xué)生管理系統(tǒng)
這篇文章主要為大家詳細介紹了基于SSM實現(xiàn)學(xué)生管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-12-12
Java中final關(guān)鍵字的使用與注意總結(jié)
這篇文章主要給大家介紹了關(guān)于Java中final關(guān)鍵字的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者使用Java具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08
Java?ArrayList遍歷foreach與iterator時remove的區(qū)別
這篇文章主要介紹了Java?ArrayList遍歷foreach與iterator時remove的區(qū)別,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的朋友可以參考一下2022-07-07

