本文整理汇总了Java中com.github.pagehelper.Page类的典型用法代码示例。如果您正苦于以下问题:Java Page类的具体用法?Java Page怎么用?Java Page使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Page类属于com.github.pagehelper包,在下文中一共展示了Page类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMapperWithStartPage
import com.github.pagehelper.Page; //导入依赖的package包/类
/**
* 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
*/
@Test
public void testMapperWithStartPage() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<Country> list = countryMapper.selectAll();
assertEquals(1, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
示例2: getUserList
import com.github.pagehelper.Page; //导入依赖的package包/类
@GetMapping("/userListByPage.json")
@ResponseBody
@ApiOperation(value = "分页查询用户列表", notes = "不传分页默认1页15条")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "页码"),
@ApiImplicitParam(name = "pageSize", value = "条数")
})
public JsonResponse getUserList(@Validated({Search.class}) UserQuery user,
BindingResult bindingResult,
PageKey pageKey)
throws ValidateException {
BindingResultUtil.validateResult(bindingResult);
Page<Object> objects = PageHelper.startPage(pageKey.getPage(), pageKey.getPageSize(), true);
UserExample example = new UserExample();
example.createCriteria().andUserNameLike(StringUtil.turn2LikeStr(user.getName()));
JsonResponse json = new JsonResponse();
List<User> users = userMapper.selectByExample(example);
json.putData("list", users);
System.out.println("**********共有" + objects.getTotal() + "条数据*********");
// redisTemplate.opsForList().rightPushAll("userList", users);
return json;
}
示例3: successWrapper
import com.github.pagehelper.Page; //导入依赖的package包/类
public static Map<String, Object> successWrapper(Page page){
Map resultMap = new HashMap();
resultMap.put("code",200);
resultMap.put("info","success");
Map<String, Object> paginInfo = new HashMap<String, Object>();
if( page != null && page.size() > 0 ) {
long totalNum =page.getTotal();
long totalPage =page.getPages();
paginInfo.put("count", totalNum );
paginInfo.put( "page", page.getPageNum());
paginInfo.put( "pageCount", totalPage );
paginInfo.put("list",page);
} else {
paginInfo.put( "count", 0 );
paginInfo.put( "page", 0 );
paginInfo.put( "pageCount", 0 );
}
resultMap.put("object", paginInfo);
return resultMap;
}
示例4: processPageParameter
import com.github.pagehelper.Page; //导入依赖的package包/类
@Override
public Object processPageParameter(MappedStatement ms, Map<String, Object> paramMap, Page page, BoundSql boundSql, CacheKey pageKey) {
paramMap.put(PAGEPARAMETER_FIRST, page.getPageSize());
paramMap.put(PAGEPARAMETER_SECOND, page.getStartRow());
//处理pageKey
pageKey.update(page.getPageSize());
pageKey.update(page.getStartRow());
//处理参数配置
if (boundSql.getParameterMappings() != null) {
List<ParameterMapping> newParameterMappings = new ArrayList<ParameterMapping>();
if (boundSql != null && boundSql.getParameterMappings() != null) {
newParameterMappings.addAll(boundSql.getParameterMappings());
}
if (page.getPageSize() > 0) {
newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_FIRST, Integer.class).build());
}
if (page.getStartRow() > 0) {
newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class).build());
}
MetaObject metaObject = MetaObjectUtil.forObject(boundSql);
metaObject.setValue("parameterMappings", newParameterMappings);
}
return paramMap;
}
示例5: processPageParameter
import com.github.pagehelper.Page; //导入依赖的package包/类
@Override
public Object processPageParameter(MappedStatement ms, Map<String, Object> paramMap, Page page, BoundSql boundSql, CacheKey pageKey) {
paramMap.put(PAGEPARAMETER_FIRST, page.getStartRow());
paramMap.put(PAGEPARAMETER_SECOND, page.getPageSize());
//处理pageKey
pageKey.update(page.getStartRow());
pageKey.update(page.getPageSize());
//处理参数配置
if (boundSql.getParameterMappings() != null) {
List<ParameterMapping> newParameterMappings = new ArrayList<ParameterMapping>();
if (page.getStartRow() > 0) {
newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_FIRST, Integer.class).build());
}
if (page.getPageSize() > 0) {
newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class).build());
}
if (boundSql != null && boundSql.getParameterMappings() != null) {
newParameterMappings.addAll(boundSql.getParameterMappings());
}
MetaObject metaObject = MetaObjectUtil.forObject(boundSql);
metaObject.setValue("parameterMappings", newParameterMappings);
}
return paramMap;
}
示例6: processPageParameter
import com.github.pagehelper.Page; //导入依赖的package包/类
@Override
public Object processPageParameter(MappedStatement ms, Map<String, Object> paramMap, Page page, BoundSql boundSql, CacheKey pageKey) {
paramMap.put(PAGEPARAMETER_FIRST, page.getStartRow());
paramMap.put(PAGEPARAMETER_SECOND, page.getPageSize());
//处理pageKey
pageKey.update(page.getStartRow());
pageKey.update(page.getPageSize());
//处理参数配置
if (boundSql.getParameterMappings() != null) {
List<ParameterMapping> newParameterMappings = new ArrayList<ParameterMapping>();
if (boundSql != null && boundSql.getParameterMappings() != null) {
newParameterMappings.addAll(boundSql.getParameterMappings());
}
if (page.getStartRow() == 0) {
newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class).build());
} else {
newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_FIRST, Integer.class).build());
newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class).build());
}
MetaObject metaObject = MetaObjectUtil.forObject(boundSql);
metaObject.setValue("parameterMappings", newParameterMappings);
}
return paramMap;
}
示例7: afterPage
import com.github.pagehelper.Page; //导入依赖的package包/类
@Override
public Object afterPage(List pageList, Object parameterObject, RowBounds rowBounds) {
Page page = getLocalPage();
if (page == null) {
return pageList;
}
page.addAll(pageList);
if (!page.isCount()) {
page.setTotal(-1);
} else if ((page.getPageSizeZero() != null && page.getPageSizeZero()) && page.getPageSize() == 0) {
page.setTotal(pageList.size());
} else if(page.isOrderByOnly()){
page.setTotal(pageList.size());
}
return page;
}
示例8: testLeftjoin
import com.github.pagehelper.Page; //导入依赖的package包/类
/**
* left join的count查询sql特殊
*/
@Test
public void testLeftjoin() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
try {
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<Country> list = countryMapper.selectLeftjoin();
assertEquals(1, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(2, 10);
list = countryMapper.selectLeftjoin();
assertEquals(11, list.get(0).getId());
assertEquals(10, list.size());
assertEquals(183, ((Page<?>) list).getTotal());
} finally {
sqlSession.close();
}
}
示例9: outPage
import com.github.pagehelper.Page; //导入依赖的package包/类
public static <T, TO> PageInfo<TO> outPage(Page<T> page, List<TO> tos) {
if (page == null)
return new PageInfo<TO>();
int pageSize = page.getPageSize();
int pageNo = page.getPageNum();
long total = page.getTotal();
return new PageInfo<TO>(pageNo, pageSize, total, tos);
}
示例10: loginSystem
import com.github.pagehelper.Page; //导入依赖的package包/类
/**
* 登录
* @param userName
* @param pwd(密文)
* @return
*/
@Override
public SysUser loginSystem(String userName, String password) {
List<Model> conditions = MyBatisUtil.parseBase("LOGIN_NAME,=,"+userName,"PASSWORD,=,"+password);
Page<SysUser> pages = getBaseMapper().selectExtend(conditions, null, null);
if (pages.size()==1) {
getBaseMapper().updateState(pages.get(0).getPk(), "LOGIN_TIME", DateUtil.format(DateUtil.YMD_HMS, new Date()), pages.get(0).getPk());
return pages.get(0);
}
return null;
}
示例11: checkLoginName
import com.github.pagehelper.Page; //导入依赖的package包/类
/**
* 验证用户名是否可用
* @param userName
* @return
*/
@Override
public int checkLoginName(String userName) {
List<Model> conditions = MyBatisUtil.parseBase("LOGIN_NAME,=,"+userName);
List<String> columns = new ArrayList<>();
columns.add("count(1) as count");
Page<SysUser> pages = getBaseMapper().selectExtend(conditions, columns, null);
if (pages.size()==0) {
return 0;
}
return pages.get(0).getCount();
}
示例12: findByPage
import com.github.pagehelper.Page; //导入依赖的package包/类
/**
* 分页查询
*
* @param queryInfo
* @param pageNum
* @param pageSize
* @param orderBy
* @return
*/
@Override
@Logger(model = LogEnum.SysUser, type = LogOperateEnum.Select, title = "")
public Json findByPage(SysUser queryInfo, int pageNum, int pageSize,String orderBy) {
Json json = new Json();
Page<SysUser> result = service.findByPage(queryInfo,pageNum,pageSize,orderBy);
if (result == null) {
return ErrorConfig.getSystemErrorJson();
}
result.forEach((su)->{
su.setPassword(null);
});
json.setSuccess(true).setObj(result).setTotal(result.getPages());
return json;
}
示例13: findAll
import com.github.pagehelper.Page; //导入依赖的package包/类
/**
* 查询所有
*
* @param queryInfo
* @param orderBy
* @return
*/
@Override
@Logger(model = LogEnum.SysUser, type = LogOperateEnum.Select, title = "")
public Json findAll(SysUser queryInfo, String orderBy) {
Json json = new Json();
Page<SysUser> result = service.findAll(queryInfo,orderBy);
if (result == null) {
return ErrorConfig.getSystemErrorJson();
}
result.forEach((su)->{
su.setPassword(null);
});
json.setSuccess(true).setObj(result);
return json;
}
示例14: findByExport
import com.github.pagehelper.Page; //导入依赖的package包/类
/**
* 导出
*
* @param conditions
* @param orderBy
* @return
*/
@Override
@Logger(model = LogEnum.SysUser, type = LogOperateEnum.Export, title = "")
public Json findByExport(List<Model> conditions, String orderBy) {
Json json = new Json();
Page<SysUser> result = service.findAll(conditions,orderBy);
if (result == null) {
return ErrorConfig.getSystemErrorJson();
}
result.forEach((su)->{
su.setPassword(null);
});
json.setSuccess(true).setObj(result);
return json;
}
示例15: deserialze
import com.github.pagehelper.Page; //导入依赖的package包/类
@SuppressWarnings({ "unchecked"})
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
if (parser.getLexer().token() == JSONToken.NULL) {
parser.getLexer().nextToken(JSONToken.COMMA);
return null;
}
String input = parser.getInput();
// final String inputValue = input.replaceAll("\\{.+list:\\[(.++)\\]\\}", "$1");
// ReflectionUtil.setField(ReflectionUtil.findField(parser.getClass(), "input"), parser,inputValue );
Page<T> list = null;
if (null==parser.getInput()||"null".equals(input)) {
return null;
}
JSONObject jo = parser.parseObject();
JSONArray ja = jo.getJSONArray("list");
if (ja!=null) {
List<T> vList = (List<T>) ja;
list = new Page<>();
list.addAll(vList);
list.setTotal(jo.getIntValue("total"));
}
return (T) list;
}