selectMapsPage是MyBatis-Plus提供的一个分页查询方法,它允许用户根据指定的条件进行分页查询,并将查询结果以Map<String, Object>的形式返回。这个方法特别适用于当开发者只需要查询部分字段而不是全部字段时,因为它可以减少不必要的数据传输和处理。 2. selectMapsPage方法的基本语法结构 java Page<Map<...
使用selectMaps来实现一下只需要对象的一部分属性。 1packagecom.kaven.mybatisplus.dao;23importcom.baomidou.mybatisplus.core.conditions.query.QueryWrapper;4importcom.baomidou.mybatisplus.core.toolkit.Wrappers;5importcom.kaven.mybatisplus.entity.User;6importorg.junit.Test;7importorg.junit.runner.RunWith;...
@TestpublicvoidselectMapsPage(){ QueryWrapper<User> wrapper =newQueryWrapper<User>();// wrapper.like("name", "王");intpageNum=1;// 当前页intpageSize=3;// 每页大小// Page<User> 修改为 IPage<Map<String, Object>>// Page<User> page = new Page<>(pageNum, pageSize); // selectMapsP...
再来看一下BaseMapper提供的分页查询方法,需要传入一个Page类型的分页参数,里面传递了第几页和每页多少个元素,MyBatisPlus内部就会去根据分页信息,查询出总数,自动进行分页。 <P extends IPage<T>> P selectPage(P page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper); selectMapsPage()方法与上面的方法一样...
(E page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper); /** * 根据 Wrapper 条件,查询全部记录(并翻页) * * @param page 分页查询条件 * @param queryWrapper 实体对象封装操作类 */ <E extends IPage<Map<String, Object>>> E selectMapsPage(E page, @Param(Constants.WRAPPER) Wrapper<T> ...
MyBatis-Plus 之selectMaps、selectObjs、selectCount、selectOne 首先创建一个数据库表,如下图所示: 然后创建一个Spring Boot项目,pom.xml和配置如下: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http:///POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...
//分页查询@TestpublicvoidselectUserByPage2(){Page<Map<String,Object>>mapPage=newPage<>(2,2);QueryWrapper<User>wrapper=newQueryWrapper<>();wrapper.like("remark","老师");IPage<Map<String,Object>>iPage=userMapper.selectMapsPage(mapPage,wrapper);//总页数System.out.println("总页数: "+iPage...
new SelectMaps(), new SelectMapsPage(), new SelectObjs(), new SelectList(), new SelectPage() ).collect(toList()); } } 方案二个人认为没有什么必要,这种扩展方式是为了增加一些mybatis-plus未支持的定式需求。而我们的目标相对简单,所以使用方案一更高效。
ge("age",26); Page<User> page = new Page<>(1, 2); IPage<Map<String,Object>> userIPage = userMapper.selectMapsPage(page, wrapper); System.out.println("总条数"+userIPage.getTotal()); System.out.println("总页数"+userIPage.getPages()); } 本文参与 腾讯云自媒体同步曝光计划,分享自...