您好,登錄后才能下訂單哦!
本篇內容主要講解“oracle+mybatis-plus+springboot怎么實現分頁查詢”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“oracle+mybatis-plus+springboot怎么實現分頁查詢”吧!
1、建一個配置類
package com.sie.demo.config; import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * @author liaozhifeng * @date 2021/7/31 11:14 * @Version 1.0 */ @Configuration @ConditionalOnClass(value = {PaginationInterceptor.class}) public class MybatisPlusConfig { // 最新版 @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); // 數據庫的配置DbType.ORACLE 根據自己的數據庫選擇 interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.ORACLE)); return interceptor; } }
package com.sie.demo.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.sie.demo.entity.Users; import com.sie.demo.entity.vo.PageUserVo; import com.sie.demo.mapper.UserMapper; import com.sie.demo.service.UserService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.util.DigestUtils; import javax.annotation.Resource; import javax.servlet.http.HttpSession; import java.util.List; /** * @author liaozhifeng * @date 2021/7/27 14:03 * @Version 1.0 */ @Service @Slf4j public class UserServiceImpl extends ServiceImpl<UserMapper, Users> implements UserService { @Resource UserMapper userMapper; /** * 分頁查詢用戶 * @param currentPage * @param pageSize * @return */ @Override public PageUserVo selectAll(long currentPage, long pageSize) { IPage<Users> userPage = new Page<>(currentPage, pageSize);//參數一是當前頁,參數二是每頁個數 IPage<Users> iPage = userMapper.selectPage(userPage, null); List<Users> list = iPage.getRecords(); Long total = iPage.getTotal(); PageUserVo pageUserVo = new PageUserVo(list, total); return pageUserVo; } }
package com.sie.demo.controller; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.sie.demo.entity.RetCode; import com.sie.demo.entity.RetResponse; import com.sie.demo.entity.RetResult; import com.sie.demo.entity.Users; import com.sie.demo.entity.vo.PageUserVo; import com.sie.demo.service.impl.UserServiceImpl; import com.sie.demo.util.TokenUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpSession; import java.util.List; @Controller @RestController @RequestMapping("user") @Slf4j public class UserController { @Autowired UserServiceImpl userService; /** * * * @param currentPage * @param pageSize * @return */ @GetMapping("selectAll") public RetResult<PageUserVo> selectAll(long currentPage, long pageSize) { log.info(currentPage+pageSize+"========================="); PageUserVo pageUserVo = userService.selectAll(currentPage,pageSize); return RetResponse.makeOKRsp(pageUserVo); } }
到此,相信大家對“oracle+mybatis-plus+springboot怎么實現分頁查詢”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。