com.github.pagehelper.PageHelper类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(638)

本文整理了Java中com.github.pagehelper.PageHelper类的一些代码示例,展示了PageHelper类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PageHelper类的具体详情如下:
包路径:com.github.pagehelper.PageHelper
类名称:PageHelper

PageHelper介绍

[英]Mybatis - 通用分页拦截器
项目地址 : http://git.oschina.net/free/Mybatis_PageHelper
[中]Mybatis-通用分页拦截器
项目地址 : http://git.oschina.net/free/Mybatis_PageHelper

代码示例

代码示例来源:origin: macrozheng/mall

@Override
public List<SmsFlashPromotionProduct> list(Long flashPromotionId, Long flashPromotionSessionId, Integer pageSize, Integer pageNum) {
  PageHelper.startPage(pageNum,pageSize);
  return relationDao.getList(flashPromotionId,flashPromotionSessionId);
}

代码示例来源:origin: lihengming/spring-boot-api-project-seed

@Bean
public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
  SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
  factory.setDataSource(dataSource);
  factory.setTypeAliasesPackage(MODEL_PACKAGE);
  //配置分页插件,详情请查阅官方文档
  PageHelper pageHelper = new PageHelper();
  Properties properties = new Properties();
  properties.setProperty("pageSizeZero", "true");//分页尺寸为0时查询所有纪录不再执行分页
  properties.setProperty("reasonable", "true");//页码<=0 查询第一页,页码>=总页数查询最后一页
  properties.setProperty("supportMethodsArguments", "true");//支持通过 Mapper 接口参数来传递分页参数
  pageHelper.setProperties(properties);
  //添加插件
  factory.setPlugins(new Interceptor[]{pageHelper});
  //添加XML目录
  ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
  factory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
  return factory.getObject();
}

代码示例来源:origin: shuzheng/zheng

@Override
public List<Record> selectByExampleForOffsetPage(Example example, Integer offset, Integer limit) {
  try {
    DynamicDataSource.setDataSource(DataSourceEnum.SLAVE.getName());
    Method selectByExample = mapper.getClass().getDeclaredMethod("selectByExample", example.getClass());
    PageHelper.offsetPage(offset, limit, false);
    Object result = selectByExample.invoke(mapper, example);
    return (List<Record>) result;
  } catch (IllegalAccessException e) {
    e.printStackTrace();
  } catch (InvocationTargetException e) {
    e.printStackTrace();
  } catch (NoSuchMethodException e) {
    e.printStackTrace();
  }
  DynamicDataSource.clearDataSource();
  return null;
}

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

protected Map<String, Object> selectByPageNumSize(QueryRequest request, Supplier<?> s) {
    PageHelper.startPage(request.getPageNum(), request.getPageSize());
    PageInfo<?> pageInfo = new PageInfo<>((List<?>) s.get());
    PageHelper.clearPage();
    return getDataTable(pageInfo);
  }
}

代码示例来源:origin: cjbi/wetech-admin

@Override
public PageResultSet<Group> findByPage(GroupQuery groupQuery) {
  if (!StringUtils.isEmpty(groupQuery.getOrderBy())) {
    PageHelper.orderBy(groupQuery.getOrderBy());
  }
  Weekend<Group> weekend = Weekend.of(Group.class);
  WeekendCriteria<Group, Object> criteria = weekend.weekendCriteria();
  if (!StringUtils.isEmpty(groupQuery.getName())) {
    criteria.andLike(Group::getName, groupQuery.getName());
  }
  PageResultSet<Group> resultSet = new PageResultSet<>();
  Page page = PageHelper.offsetPage(groupQuery.getOffset(), groupQuery.getLimit()).doSelectPage(() -> groupMapper.selectByExample(weekend));
  resultSet.setRows(page);
  resultSet.setTotal(page.getTotal());
  return resultSet;
}

代码示例来源:origin: cjbi/wetech-admin

@Override
public PageResultSet<RoleDto> findByPage(RoleQuery roleQuery) {
  PageHelper.offsetPage(roleQuery.getOffset(), roleQuery.getLimit());
  if(!StringUtils.isEmpty(roleQuery.getOrderBy())) {
    PageHelper.orderBy(roleQuery.getOrderBy());
  }
  Weekend<Role> example = Weekend.of(Role.class);
  WeekendCriteria<Role, Object> criteria = example.weekendCriteria();
  if(!StringUtils.isEmpty(roleQuery.getRole())) {
    criteria.andLike(Role::getRole,"%" + roleQuery.getRole() + "%");
  }
  if(!StringUtils.isEmpty(roleQuery.getDescription())) {
    criteria.andLike(Role::getDescription,"%" + roleQuery.getDescription() + "%");
  }
  PageResultSet<RoleDto> resultSet = new PageResultSet<>();
  List<RoleDto> dtoList = new ArrayList<>();
  roleMapper.selectByExample(example).forEach(r -> {
    RoleDto dto = new RoleDto(r);
    dto.setResourceNames(getResourceNames(r.getResourceIdList()));
    dtoList.add(dto);
  });
  long total = roleMapper.selectCountByExample(example);
  resultSet.setRows(dtoList);
  resultSet.setTotal(total);
  return resultSet;
}

代码示例来源:origin: macrozheng/mall

@Override
public List<OmsOrder> list(OmsOrderQueryParam queryParam, Integer pageSize, Integer pageNum) {
  PageHelper.startPage(pageNum, pageSize);
  return orderDao.getList(queryParam);
}

代码示例来源:origin: jmdhappy/xxpay-master

@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
  SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
  sqlSessionFactoryBean.setDataSource(dataSource());
  //mybatis分页
  PageHelper pageHelper = new PageHelper();
  Properties props = new Properties();
  props.setProperty("dialect", "mysql");
  props.setProperty("reasonable", "true");
  props.setProperty("supportMethodsArguments", "true");
  props.setProperty("returnPageInfo", "check");
  props.setProperty("params", "count=countSql");
  pageHelper.setProperties(props); //添加插件
  sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
  PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
  sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:org/xxpay/shop/dao/mapper/*.xml"));
  return sqlSessionFactoryBean.getObject();
}

代码示例来源:origin: cjbi/wetech-admin

@Override
public PageResultSet<UserDto> findByPage(UserQuery userQuery) {
  if(!StringUtils.isEmpty(userQuery.getOrderBy())) {
    PageHelper.orderBy(userQuery.getOrderBy());
  }
  Weekend<User> example = Weekend.of(User.class);
  WeekendCriteria<User, Object> criteria = example.weekendCriteria();
  if (!StringUtils.isEmpty(userQuery.getUsername())) {
    criteria.andLike(User::getUsername, "%" + userQuery.getUsername() + "%");
  }
  if(userQuery.getLocked() != null) {
    criteria.andEqualTo(User::getLocked,userQuery.getLocked());
  }
  List<UserDto> dtoList = new ArrayList<>();
  PageHelper.offsetPage(userQuery.getOffset(), userQuery.getLimit());
  userMapper.selectByExample(example).forEach(u -> {
    UserDto dto = new UserDto(u);
    dto.setOrganizationName(getOrganizationName(Long.valueOf(dto.getOrganizationId())));
    dto.setRoleNames(getRoleNames(dto.getRoleIdList()));
    dto.setGroupNames(getGroupNames(dto.getGroupIdList()));
    dtoList.add(dto);
  });
  long total = userMapper.selectCountByExample(example);
  PageResultSet<UserDto> resultSet = new PageResultSet<>();
  resultSet.setRows(dtoList);
  resultSet.setTotal(total);
  return resultSet;
}

代码示例来源:origin: shuzheng/zheng

@Override
public List<Record> selectByExampleWithBLOBsForOffsetPage(Example example, Integer offset, Integer limit) {
  try {
    DynamicDataSource.setDataSource(DataSourceEnum.SLAVE.getName());
    Method selectByExampleWithBLOBs = mapper.getClass().getDeclaredMethod("selectByExampleWithBLOBs", example.getClass());
    PageHelper.offsetPage(offset, limit, false);
    Object result = selectByExampleWithBLOBs.invoke(mapper, example);
    return (List<Record>) result;
  } catch (IllegalAccessException e) {
    e.printStackTrace();
  } catch (InvocationTargetException e) {
    e.printStackTrace();
  } catch (NoSuchMethodException e) {
    e.printStackTrace();
  }
  DynamicDataSource.clearDataSource();
  return null;
}

代码示例来源:origin: macrozheng/mall

@Override
public List<OmsOrderReturnApply> list(OmsReturnApplyQueryParam queryParam, Integer pageSize, Integer pageNum) {
  PageHelper.startPage(pageNum,pageSize);
  return returnApplyDao.getList(queryParam);
}

代码示例来源:origin: jmdhappy/xxpay-master

@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
  SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
  sqlSessionFactoryBean.setDataSource(dataSource());
  //mybatis分页
  PageHelper pageHelper = new PageHelper();
  Properties props = new Properties();
  props.setProperty("dialect", "mysql");
  props.setProperty("reasonable", "true");
  props.setProperty("supportMethodsArguments", "true");
  props.setProperty("returnPageInfo", "check");
  props.setProperty("params", "count=countSql");
  pageHelper.setProperties(props); //添加插件
  sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
  PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
  sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:org/xxpay/dal/dao/mapper/*.xml"));
  return sqlSessionFactoryBean.getObject();
}

代码示例来源:origin: cjbi/wetech-admin

PageHelper.orderBy(log.getOrderBy());
Page page = PageHelper.offsetPage(log.getOffset(), log.getLimit()).doSelectPage(()-> logMapper.selectByExample(example));

代码示例来源:origin: javahongxi/whatsmars

@Override
public Page<User> query(int offset, int limit) {
  return PageHelper.offsetPage(offset, limit).doSelectPage(() -> userMapper.query());
}

代码示例来源:origin: shuzheng/zheng

@Override
public List<Record> selectByExampleForStartPage(Example example, Integer pageNum, Integer pageSize) {
  try {
    DynamicDataSource.setDataSource(DataSourceEnum.SLAVE.getName());
    Method selectByExample = mapper.getClass().getDeclaredMethod("selectByExample", example.getClass());
    PageHelper.startPage(pageNum, pageSize, false);
    Object result = selectByExample.invoke(mapper, example);
    return (List<Record>) result;
  } catch (IllegalAccessException e) {
    e.printStackTrace();
  } catch (InvocationTargetException e) {
    e.printStackTrace();
  } catch (NoSuchMethodException e) {
    e.printStackTrace();
  }
  DynamicDataSource.clearDataSource();
  return null;
}

代码示例来源:origin: mrdear/JavaWEB

PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("reasonable", "true");
properties.setProperty("returnPageInfo", "check");
properties.setProperty("params", "count=countSql");
pageHelper.setProperties(properties);

代码示例来源:origin: liunian1004/vua

@Override
public List<Record> selectByExampleWithBLOBsForOffsetPage(Example example, Integer offset, Integer limit) {
  try {
    Method selectByExampleWithBLOBs = mapper.getClass().getDeclaredMethod("selectByExampleWithBLOBs", example.getClass());
    PageHelper.offsetPage(offset, limit);
    Object result = selectByExampleWithBLOBs.invoke(mapper, example);
    return (List<Record>)result;
  } catch (Exception e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: shuzheng/zheng

@Override
public List<Record> selectByExampleWithBLOBsForStartPage(Example example, Integer pageNum, Integer pageSize) {
  try {
    DynamicDataSource.setDataSource(DataSourceEnum.SLAVE.getName());
    Method selectByExampleWithBLOBs = mapper.getClass().getDeclaredMethod("selectByExampleWithBLOBs", example.getClass());
    PageHelper.startPage(pageNum, pageSize, false);
    Object result = selectByExampleWithBLOBs.invoke(mapper, example);
    return (List<Record>) result;
  } catch (IllegalAccessException e) {
    e.printStackTrace();
  } catch (InvocationTargetException e) {
    e.printStackTrace();
  } catch (NoSuchMethodException e) {
    e.printStackTrace();
  }
  DynamicDataSource.clearDataSource();
  return null;
}

代码示例来源:origin: xuyaohui/cloud-ida-cli

@Bean
  public PageHelper pageHelper() {
    PageHelper pageHelper = new PageHelper();
    Properties p = new Properties();
    p.setProperty("reasonable", "true");
    pageHelper.setProperties(p);
    return pageHelper;
  }
}

代码示例来源:origin: liunian1004/vua

@Override
public List<Record> selectByExampleForOffsetPage(Example example, Integer offset, Integer limit) {
  try {
    Method selectByExample = mapper.getClass().getDeclaredMethod("selectByExample", example.getClass());
    PageHelper.offsetPage(offset, limit, false);
    Object result = selectByExample.invoke(mapper, example);
    return (List<Record>) result;
  } catch (Exception e) {
    e.printStackTrace();
  }
  return null;
}

相关文章