com.github.pagehelper.PageInfo分页插件的12种用法
PageInfo分页插件的用法
·
用法一:
@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);
}
更多推荐
已为社区贡献10条内容
所有评论(0)