com.github.pagehelper.PageInfo分页插件的12种用法

简介: com.github.pagehelper.PageInfo分页插件的12种用法

用法一:

@GetMapping("/_useSqlhelper_over_pageHelper")
public Page list_sqlhelper_over_pageHelper(
        @RequestParam(name = "pageNo") Integer pageNo,
        @RequestParam(name = "pageSize") Integer pageSize,
        @RequestParam(name = "sort", required = false) String sort,
        @RequestParam(value = "countColumn", required = false) String countColumn) {
    Page page = PageHelper.offsetPage(pageNo, pageSize);
    // Page page = PageHelper.startPage(pageNo, pageSize, sort);
    page.setCountColumn(countColumn);
    User queryCondition = new User();
    queryCondition.setAge(10);
    List<User> users = userDao.selectByLimit(queryCondition);
    String json = JSONBuilderProvider.simplest().toJson(users);
    System.out.println(json);
    json = JSONBuilderProvider.simplest().toJson(users);
    System.out.println(json);
    PageInfo pageInfo1 = new PageInfo(page);
    json = JSONBuilderProvider.simplest().toJson(pageInfo1);
    System.out.println(json);
    PageInfo pageInfo2 = new PageInfo(users);
    json = JSONBuilderProvider.simplest().toJson(pageInfo2);
    System.out.println(json);
    return page;
}

用法二:

@Permission(type = ResourceType.ORGANIZATION)
@ApiOperation(value = "查询状态机方案列表")
@CustomPageRequest
@GetMapping
public ResponseEntity<PageInfo<StateMachineSchemeVO>> pagingQuery(@ApiIgnore
                                                               @SortDefault(value = "id", direction = Sort.Direction.DESC) PageRequest pageRequest,
                                                                  @PathVariable("organization_id") Long organizationId,
                                                                  @RequestParam(required = false) String name,
                                                                  @RequestParam(required = false) String description,
                                                                  @RequestParam(required = false) String[] param) {
    StateMachineSchemeVO schemeDTO = new StateMachineSchemeVO();
    schemeDTO.setOrganizationId(organizationId);
    schemeDTO.setName(name);
    schemeDTO.setDescription(description);
    return new ResponseEntity<>(schemeService.pageQuery(organizationId, pageRequest, schemeDTO, ParamUtils.arrToStr(param)), HttpStatus.OK);
}

用法三:

/**
 * 分页查询
 *
 * @param pageNum
 * @param pageSize
 * @param tbSysUserJson
 * @return
 */
@RequestMapping(value = "page/{pageNum}/{pageSize}", method = RequestMethod.GET)
public BaseResult page(
        @PathVariable(required = true) int pageNum,
        @PathVariable(required = true) int pageSize,
        @RequestParam(required = false) String tbSysUserJson
) throws Exception {
    TbSysUser tbSysUser = null;
    if (tbSysUserJson != null) {
        tbSysUser = MapperUtils.json2pojo(tbSysUserJson, TbSysUser.class);
    }
    PageInfo pageInfo = adminService.page(pageNum, pageSize, tbSysUser);
    // 分页后的结果集
    List<TbSysUser> list = pageInfo.getList();
    // 封装 Cursor 对象
    BaseResult.Cursor cursor = new BaseResult.Cursor();
    cursor.setTotal(new Long(pageInfo.getTotal()).intValue());
    cursor.setOffset(pageInfo.getPageNum());
    cursor.setLimit(pageInfo.getPageSize());
    return BaseResult.ok(list, cursor);
}

用法四:

@RequiresPermissions("admin:ad:list")
@RequiresPermissionsDesc(menu={"推广管理" , "广告管理"}, button="查询")
@GetMapping("/list")
public Object list(String name, String content,
                   @RequestParam(defaultValue = "1") Integer page,
                   @RequestParam(defaultValue = "10") Integer limit,
                   @Sort @RequestParam(defaultValue = "add_time") String sort,
                   @Order @RequestParam(defaultValue = "desc") String order) {
    List<LitemallAd> adList = adService.querySelective(name, content, page, limit, sort, order);
    long total = PageInfo.of(adList).getTotal();
    Map<String, Object> data = new HashMap<>();
    data.put("total", total);
    data.put("items", adList);
    return ResponseUtil.ok(data);
}

用法五:

@PostMapping(value = "/request/audit_query")
public PageInfo<RequestAudit> requestAuditQuery(HttpServletRequest request) {
  Map<String, Object> dataMap = new HashMap<>();
  dataMap.put(CommonParameter.ID, request.getParameter(CommonParameter.ID));
  dataMap.put("prId", request.getParameter("prId"));
  dataMap.put(CommonParameter.PRODUCT_ID, request.getParameter(CommonParameter.PRODUCT_ID));
  dataMap.put(CommonParameter.SUBMITTER, request.getParameter(CommonParameter.SUBMITTER));
  dataMap.put("auditStatus", request.getParameter("auditStatus"));
  if (!StringUtils.isEmpty(request.getParameter("submitTimeStart"))) {
    dataMap.put("submitTimeStart", request.getParameter("submitTimeStart") + " 00:00:00");
  }
  if (!StringUtils.isEmpty(request.getParameter("submitTimeEnd"))) {
    dataMap.put("submitTimeEnd", request.getParameter("submitTimeEnd") + " 23:59:59");
  }
  int pageNum = ParameterThreadLocal.getPageNum();
  int pageSize = ParameterThreadLocal.getPageSize();
  PageHelper.startPage(pageNum, pageSize);
  List<RequestAudit> requestAudits = requestAuditService.requestAuditQuery(dataMap);
  PageInfo<RequestAudit> pageInfo = new PageInfo<>(requestAudits);
  return pageInfo;
}

用法六:

/**
 * 查询订阅者列表.
 *
 * @param tpcMqConsumer the tpc mq consumer
 *
 * @return the wrapper
 */
@PostMapping(value = "/querySubscribeListWithPage")
@ApiOperation(httpMethod = "POST", value = "查询订阅者列表")
public Wrapper<PageInfo<TpcMqSubscribeVo>> querySubscribeListWithPage(@ApiParam(name = "consumer", value = "Mq消费者") @RequestBody TpcMqConsumer tpcMqConsumer) {
  logger.info("查询Mq订阅列表tpcMqConsumerQuery={}", tpcMqConsumer);
  PageHelper.startPage(tpcMqConsumer.getPageNum(), tpcMqConsumer.getPageSize());
  tpcMqConsumer.setOrderBy("update_time desc");
  List<TpcMqSubscribeVo> list = tpcMqConsumerService.listSubscribeVoWithPage(tpcMqConsumer);
  PageInfo<TpcMqSubscribeVo> pageInfo = new PageInfo<>(list);
  if (PublicUtil.isNotEmpty(list)) {
    Map<Long, TpcMqSubscribeVo> tpcMqSubscribeVoMap = this.trans2Map(list);
    List<Long> subscribeIdList = new ArrayList<>(tpcMqSubscribeVoMap.keySet());
    List<TpcMqSubscribeVo> tagVoList = tpcMqConsumerService.listSubscribeVo(subscribeIdList);
    for (TpcMqSubscribeVo vo : tagVoList) {
      Long subscribeId = vo.getId();
      if (!tpcMqSubscribeVoMap.containsKey(subscribeId)) {
        continue;
      }
      TpcMqSubscribeVo tpcMqSubscribeVo = tpcMqSubscribeVoMap.get(subscribeId);
      tpcMqSubscribeVo.setTagVoList(vo.getTagVoList());
    }
    pageInfo.setList(new ArrayList<>(tpcMqSubscribeVoMap.values()));
  }
  return WrapMapper.ok(pageInfo);
}

用法七:

@RequiresPermissions("admin:user:list")
@RequiresPermissionsDesc(menu={"用户管理" , "会员管理"}, button="查询")
@GetMapping("/list")
public Object list(String username, String mobile,
                   @RequestParam(defaultValue = "1") Integer page,
                   @RequestParam(defaultValue = "10") Integer limit,
                   @Sort @RequestParam(defaultValue = "add_time") String sort,
                   @Order @RequestParam(defaultValue = "desc") String order) {
    List<LitemallUser> userList = userService.querySelective(username, mobile, page, limit, sort, order);
    long total = PageInfo.of(userList).getTotal();
    Map<String, Object> data = new HashMap<>();
    data.put("total", total);
    data.put("items", userList);
    return ResponseUtil.ok(data);
}

用法八:

@RequiresPermissions("admin:history:list")
@RequiresPermissionsDesc(menu={"用户管理" , "搜索历史"}, button="查询")
@GetMapping("/list")
public Object list(String userId, String keyword,
                   @RequestParam(defaultValue = "1") Integer page,
                   @RequestParam(defaultValue = "10") Integer limit,
                   @Sort @RequestParam(defaultValue = "add_time") String sort,
                   @Order @RequestParam(defaultValue = "desc") String order) {
    List<LitemallSearchHistory> footprintList = searchHistoryService.querySelective(userId, keyword, page, limit, sort, order);
    long total = PageInfo.of(footprintList).getTotal();
    Map<String, Object> data = new HashMap<>();
    data.put("total", total);
    data.put("items", footprintList);
    return ResponseUtil.ok(data);
}

用法九:

/**
     * datasource test
     * @return
     */
    //    @Transactional
    @GetMapping("test")
    public String test() {
        PageHelper.startPage(1, 1);
        List<UserRequestData> userRequestData = userRequestDataMapper.selectAll();
        PageInfo<UserRequestData> userRequestDataPageInfo = new PageInfo<>(userRequestData);
        System.out.println(userRequestDataPageInfo);
        PageHelper.startPage(1, 2);
        List<Test> tests = testMapper.selectAll();
        PageInfo<Test> testPageInfo = new PageInfo<>(tests);
        System.out.println(testPageInfo);
        return JSONObject.toJSONString(testPageInfo);
//        UserRequestData userRequestData1 = new UserRequestData();
//        userRequestData1.setUserId(11L);
//        userRequestDataMapper.insert(userRequestData1);
//        int i = 1 / 0;
//        testMapper.insert();
    }

用法十:

@RequestMapping(value = "/pageList", method = RequestMethod.POST)
public RestResponse<PageInfo<ExamPaperAnswerPageResponseVM>> pageList(@Valid ExamPaperAnswerPageVM model) {
    model.setCreateUser(getCurrentUser().getId());
    PageInfo<ExamPaperAnswer> pageInfo = examPaperAnswerService.studentPage(model);
    PageInfo<ExamPaperAnswerPageResponseVM> page = PageInfoHelper.copyMap(pageInfo, e -> {
        ExamPaperAnswerPageResponseVM vm = modelMapper.map(e, ExamPaperAnswerPageResponseVM.class);
        Subject subject = subjectService.selectById(vm.getSubjectId());
        vm.setDoTime(ExamUtil.secondToVM(e.getDoTime()));
        vm.setSystemScore(ExamUtil.scoreToVM(e.getSystemScore()));
        vm.setUserScore(ExamUtil.scoreToVM(e.getUserScore()));
        vm.setPaperScore(ExamUtil.scoreToVM(e.getPaperScore()));
        vm.setSubjectName(subject.getName());
        vm.setCreateTime(DateTimeUtil.dateFormat(e.getCreateTime()));
        return vm;
    });
    return RestResponse.ok(page);
}

用法11:

/**
 * 查询公告列表
 *
 * @param goodsSn
 * @param name
 * @param page
 * @param limit
 * @param sort
 * @param order
 * @return
 */
@RequiresPermissions("admin:article:list")
@RequiresPermissionsDesc(menu = { "推广管理", "公告管理" }, button = "查询")
@GetMapping("/list")
public Object list(String title, @RequestParam(defaultValue = "1") Integer page,
    @RequestParam(defaultValue = "10") Integer limit,
    @Sort @RequestParam(defaultValue = "add_time") String sort,
    @Order @RequestParam(defaultValue = "desc") String order) {
  logger.info("【请求开始】推广管理->公告管理->查询,请求参数:title:{},page:{}", title, page);
  List<DtsArticle> articleList = articleService.querySelective(title, page, limit, sort, order);
  long total = PageInfo.of(articleList).getTotal();
  Map<String, Object> data = new HashMap<>();
  data.put("total", total);
  data.put("items", articleList);
  logger.info("【请求结束】推广管理->公告管理->查询,响应结果:{}", JSONObject.toJSONString(data));
  return ResponseUtil.ok(data);
}

用法12:

@RequiresPermissions("admin:feedback:list")
@RequiresPermissionsDesc(menu = { "用户管理", "意见反馈" }, button = "查询")
@GetMapping("/list")
public Object list(Integer userId, String username, @RequestParam(defaultValue = "1") Integer page,
    @RequestParam(defaultValue = "10") Integer limit,
    @Sort @RequestParam(defaultValue = "add_time") String sort,
    @Order @RequestParam(defaultValue = "desc") String order) {
  logger.info("【请求开始】用户管理->意见反馈->查询,请求参数:userId:{},username:{},page:{}", userId, username, page);
  List<DtsFeedback> feedbackList = feedbackService.querySelective(userId, username, page, limit, sort, order);
  long total = PageInfo.of(feedbackList).getTotal();
  Map<String, Object> data = new HashMap<>();
  data.put("total", total);
  data.put("items", feedbackList);
  logger.info("【请求结束】用户管理->意见反馈->查询,响应结果:{}", JSONObject.toJSONString(data));
  return ResponseUtil.ok(data);
}


相关文章
|
3月前
|
数据安全/隐私保护
【Azure Developer】Github Action使用Azure/login@v1插件登录遇见错误的替代方案
【Azure Developer】Github Action使用Azure/login@v1插件登录遇见错误的替代方案
|
3月前
|
Web App开发
【无标题】推荐一个非常好用的GitHub插件
【无标题】推荐一个非常好用的GitHub插件
20 0
|
3月前
|
Web App开发 自然语言处理 iOS开发
GitHub 中文化插件
这款插件专为GitHub设计,实现菜单栏、标题及按钮等元素的汉化,并提供项目描述的人机翻译,助力新手快速上手。相较于浏览器自带翻译,准确性更高。安装需先配备Tampermonkey或Violentmonkey,随后从GreasyFork安装插件,重启GitHub即现中文界面。
31 0
|
6月前
|
Go Docker 索引
Flutter 插件站新升级: 加入优秀 GitHub 开源项目
这几天晚上抽空把 Flutter 插件站升级,现在支持插件搜索,并收录了众多优秀的 GitHub 开源项目,让您轻松发现与插件相关的精品项目。
Flutter 插件站新升级: 加入优秀 GitHub 开源项目
|
开发者
Github-谷歌插件gitzip(加速器-不用再忍受几十kb/s的煎熬了)
Github-谷歌插件gitzip(加速器-不用再忍受几十kb/s的煎熬了)
399 0
Github-谷歌插件gitzip(加速器-不用再忍受几十kb/s的煎熬了)
|
Web App开发 传感器 IDE
GitHub代码查看神器—Sourcegraph插件安装和使用
GitHub代码查看神器—Sourcegraph插件安装和使用
|
数据采集 监控 搜索推荐
Go分享好的github插件和项目
Go分享好的github插件和项目
133 0
|
Web App开发 开发工具 git
推荐三款插件,让你玩转Github
推荐三款插件,让你玩转Github
|
Web App开发 存储 数据可视化
GitHub超实用的可视化代码树插件:Octotree
GitHub超实用的可视化代码树插件:Octotree
156 0
 GitHub超实用的可视化代码树插件:Octotree
|
Web App开发 程序员 开发工具
国内Github下载很慢,用上了这个插件后,下载速度嗖嗖嗖的~!
国内Github下载很慢,用上了这个插件后,下载速度嗖嗖嗖的~!
国内Github下载很慢,用上了这个插件后,下载速度嗖嗖嗖的~!