com.github.pagehelper.PageRowBounds Java Examples
The following examples show how to use
com.github.pagehelper.PageRowBounds.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamicMapperTest.java From mybatis-dynamic-query with Apache License 2.0 | 6 votes |
@Test public void testSelectRowBoundsByDynamicQuery() { DynamicQuery<User> dynamicQuery = new DynamicQuery<>(User.class); dynamicQuery.setDistinct(true); FilterDescriptor idFilter = new FilterDescriptor("id", FilterOperator.LESS_THAN, 100); dynamicQuery.addFilters(idFilter); SortDescriptor idSort = new SortDescriptor(User::getId, SortDirection.DESC); dynamicQuery.addSorts(idSort); PageRowBounds pageRowBounds = new PageRowBounds(1, 2); List<User> users = userDao.selectRowBoundsByDynamicQuery(dynamicQuery, pageRowBounds); assertEquals(true, users.size() > 0); }
Example #2
Source File: SelectController.java From cjs_ssms with GNU General Public License v2.0 | 6 votes |
/** * 数据表grid查询 It's not good enough * @param pageIndex * @param pageSize * @param paramsMap 给criteria添加参数使用 * @return */ private Map<String, Object> getGrids(int pageIndex, int pageSize, HashMap<String, String> paramsMap) { PageRowBounds rowBounds = new PageRowBounds(pageIndex+1, pageSize); SqlSession sqlSession = MybatisHelper.getSqlSession(); Mapper mapper = (Mapper) sqlSession.getMapper(UUserMapper.class); Example example = new Example(UUser.class); Example.Criteria criteria = example.createCriteria(); /*criteria增加条件...*/ List<UUser> users = (List<UUser>) mapper.selectByExampleAndRowBounds(example, rowBounds); /*4.构造适合miniui_grid展示的map*/ Map<String, Object> map_grid = new HashedMap(); map_grid.put("total", users.size()); map_grid.put("data", users); return map_grid; }
Example #3
Source File: PageRowBoundsTest.java From Mybatis-PageHelper with MIT License | 6 votes |
/** * 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数 */ @Test public void testWithRowboundsAndCountTrue() { SqlSession sqlSession = RowBoundsHelper.getSqlSession(); UserMapper userMapper = sqlSession.getMapper(UserMapper.class); try { //limit=0,这时候相当于用分页插件求count,但是前提必须是配置rounbounds方式求count,否则都是-1 //这里由于没有配置,应该都是-1 PageRowBounds pageRowBounds = new PageRowBounds(0, -1); List<User> list = userMapper.selectAll(pageRowBounds); assertEquals(183, list.size()); //pageSize<0的时候同上 list = userMapper.selectAll(new PageRowBounds(0, -100)); assertEquals(183, list.size()); } finally { sqlSession.close(); } }
Example #4
Source File: SelectServiceImpl.java From cjs_ssms with GNU General Public License v2.0 | 5 votes |
@Override public Map<String, Object> queryGridKey(int pageNum, int pageSize, String field, String sort, HashMap<String, String> params) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException { String[] strs = params.get("key").split("_"); /*1.strs[0]:接口, strs[1]:方法*/ SqlSession sqlSession = MybatisHelper.getSqlSession(); /*2.sqlSession*/ PageRowBounds rowBounds = new PageRowBounds(pageNum, pageSize); /*3.rowBounds*/ /* 0 = {HashMap$Node@7360} "rolename" -> "0001" 1 = {HashMap$Node@7361} "key" -> "UUserMapper_gridUsers" 2 = {HashMap$Node@7362} "username" -> "0001" * */ /*1.Mapper*/ Class mapper_clz = Class.forName(MAPPER + strs[0]); Mapper mapper = (Mapper) sqlSession.getMapper(mapper_clz); /*2.Page分页操作*/ // List<Object> list = pagePojo(params, strs, mapper, pageNum, pageSize); // pojo List<Object> list = pageMap(params, strs, mapper, pageNum, pageSize); // map PageInfo page = new PageInfo(list); /*4.构造适合miniui_grid展示的map*/ Map<String, Object> map_grid = new HashedMap(); map_grid.put("total", page.getTotal()); map_grid.put("data", list); return map_grid; }
Example #5
Source File: AbstractRowBoundsDialect.java From Mybatis-PageHelper with MIT License | 5 votes |
@Override public boolean beforeCount(MappedStatement ms, Object parameterObject, RowBounds rowBounds) { if(rowBounds instanceof PageRowBounds){ PageRowBounds pageRowBounds = (PageRowBounds)rowBounds; return pageRowBounds.getCount() == null || pageRowBounds.getCount(); } return false; }
Example #6
Source File: AbstractHelperDialect.java From Mybatis-PageHelper with MIT License | 5 votes |
@Override public boolean afterCount(long count, Object parameterObject, RowBounds rowBounds) { Page page = getLocalPage(); page.setTotal(count); if (rowBounds instanceof PageRowBounds) { ((PageRowBounds) rowBounds).setTotal(count); } //pageSize < 0 的时候,不执行分页查询 //pageSize = 0 的时候,还需要执行后续查询,但是不会分页 if (page.getPageSize() < 0) { return false; } return count > ((page.getPageNum() - 1) * page.getPageSize()); }
Example #7
Source File: AbstractRowBoundsDialect.java From Mybatis-PageHelper with MIT License | 4 votes |
@Override public boolean afterCount(long count, Object parameterObject, RowBounds rowBounds) { //由于 beforeCount 校验,这里一定是 PageRowBounds ((PageRowBounds) rowBounds).setTotal(count); return count > 0; }