oracle+mybatis-plus+springboot怎么实现分页查询
短信预约 -IT技能 免费直播动态提醒
本篇内容主要讲解“oracle+mybatis-plus+springboot怎么实现分页查询”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“oracle+mybatis-plus+springboot怎么实现分页查询”吧!
建一个配置类
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; @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; }}
2、service层的代码
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; @Service@Slf4jpublic class UserServiceImpl extends ServiceImpl<UserMapper, Users> implements UserService { @Resource UserMapper userMapper; @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; }}
3、controller层 RetResult是我自己定义的一个统一返回的泛型对象
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")@Slf4jpublic class UserController { @Autowired UserServiceImpl userService; @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怎么实现分页查询”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341