当前位置:网站首页>About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller
About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller
2022-07-03 05:15:00 【A wild man about to succeed】
problem : The console shows that we have found the value , But the final returned data is null

Question why :PageWeb Of pageNum and pageSize The value of is affected by the front-end value transmission ,pageNum,totalSize suffer mybatisPlus Of page Method influence , As a result, the data cannot be displayed
Controller Class
@Slf4j
@RestController
@RequestMapping("notice")
public class NoticeController {
@Resource
private NoticeService noticeService;
/**
* View notification announcement interface
*
* @param pageWeb
* @return
*/
@GetMapping("getManagerNotice")
public ResultJson getManagerNotice(@RequestBody PageWeb<Notice> pageWeb) {
Page<Notice> page = new Page<>(pageWeb.getPageNum(), pageWeb.getPageSize());
QueryWrapper<Notice> noticeQueryWrapper = new QueryWrapper<>();
noticeQueryWrapper.eq("state", NoticeConstant.PUBLIC_ALREADY);
if (!StringUtils.isEmpty(pageWeb.getParams().getTitle())) {
noticeQueryWrapper.like("title", pageWeb.getParams().getTitle());
}
if (!StringUtils.isEmpty(pageWeb.getParams().getContent())) {
noticeQueryWrapper.like("content", pageWeb.getParams().getContent());
}
if (!StringUtils.isEmpty(pageWeb.getParams().getFromId())) {
noticeQueryWrapper.eq("from_id", pageWeb.getParams().getFromId());
}
if (!StringUtils.isEmpty(pageWeb.getParams().getToId())) {
noticeQueryWrapper.eq("to_id", pageWeb.getParams().getToId());
}
if (!StringUtils.isEmpty(pageWeb.getParams().getCreateTime())) {
noticeQueryWrapper.like("create_time", pageWeb.getParams().getCreateTime());
}
IPage<Notice> ipage = noticeService.page(page, noticeQueryWrapper);
return ResultJson.ok(PageWeb.bulidPageWeb(ipage));
}
}PageWeb<T> Encapsulate generic classes separately
package com.fourthgroup.schoolmanagementsystem.common.web;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fourthgroup.schoolmanagementsystem.common.constant.WebConstant;
import lombok.Data;
import java.util.List;
@Data
public class PageWeb<T> {
private long pageNum=1L;
private long pageSize=20L;
private long totalSize;
private T params;
private List<T> records;
public static PageWeb bulidPageWeb(IPage page) {
return new PageWeb(page.getCurrent(), page.getSize(), page.getTotal(), page.getRecords());
}
public PageWeb(long pageNum, long pageSize, long totalSize, List<T> records) {
this.pageNum = pageNum;
this.pageSize = pageSize;
this.totalSize = totalSize;
this.records = records;
}
}
stay Postman Zhongchuan ginseng (Json Format )

At this time, we did not pass pageNum and pageSize, And we are Controller Medium
Page<Notice> page = new Page<>(pageWeb.getPageNum(), pageWeb.getPageSize());
Of page What is passed in the constructor is pageWeb.getPageNum(), pageWeb.getPageSize(),
We debug debugged , stay page Method line break point

At this time, the value we get is that we are PageWeb Value assigned inside , But we Postman No value transfer , So the value we wrote before , Will be Postman The values in the are overwritten ,
Then we are PageWeb Break point in the variable of

pageNum Turned into 1,totalSize Turned into 2, but pageSize yes 0, This leads to the fact that our data cannot be displayed
because page After method execution , The obtained value will be overwritten automatically PageWeb Value ,
resolvent :
Assign value in constructor , And determine null assignment
package com.fourthgroup.schoolmanagementsystem.common.web;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fourthgroup.schoolmanagementsystem.common.constant.WebConstant;
import lombok.Data;
import java.util.List;
@Data
public class PageWeb<T> {
private long pageNum;
private long pageSize;
private long totalSize;
private T params;
private List<T> records;
public static PageWeb bulidPageWeb(IPage page) {
return new PageWeb(page.getCurrent(), page.getSize(), page.getTotal(), page.getRecords());
}
public PageWeb(long pageNum, long pageSize, long totalSize, List<T> records) {
if (pageNum== 0) {
this.pageNum = Long.valueOf(WebConstant.DEFAULT_PAGE_NO);
} else {
this.pageNum = pageNum;
}
if (pageSize == 0) {
this.pageSize = Long.valueOf(WebConstant.DEFAULT_PAGE_SIZE);
}else{
this.pageSize = pageSize;
}
this.totalSize = totalSize;
this.records = records;
}
}
continue debug
Because we judge empty in the constructor , So he will assign values to us automatically
Long.valueOf(WebConstant.DEFAULT_PAGE_NO), The default setting here is 1; Long.valueOf(WebConstant.DEFAULT_PAGE_SIZE), The default setting here is 20
On the whole ,records There is ArrayList The value of
边栏推荐
- 小学校园IP网络广播-基于校园局域网的小学IP数字广播系统设计
- 1119 pre- and post order traversals (30 points)
- Technical analysis of qianyuantong multi card aggregation router
- Redis 入门和数据类型讲解
- (subplots用法)matplotlib如何绘制多个子图(轴域)
- 动态规划——相关概念,(数塔问题)
- leetcode452. Detonate the balloon with the minimum number of arrows
- Class loading mechanism (detailed explanation of the whole process)
- 2022-02-11 daily clock in: problem fine brush
- Problems encountered in fuzzy query of SQL statements
猜你喜欢

Pessimistic lock and optimistic lock of multithreading

5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip

How to connect the network: Chapter 1 CSDN creation punch in

Unity tool Luban learning notes 1

【实战项目】自主web服务器

乾元通多卡聚合路由器的技术解析

Technical analysis of qianyuantong multi card aggregation router

Web APIs exclusivity

2022-02-12 daily clock in: problem fine brush

Handler understands the record
随机推荐
Shallow and first code
1106 lowest price in supply chain (25 points)
[backtrader source code analysis 4] use Python to rewrite the first function of backtrader: time2num, which improves the efficiency by 2.2 times
Huawei personally ended up developing 5g RF chips, breaking the monopoly of Japan and the United States
Go practice -- generate and read QR codes in golang (skip2 / go QRcode and boombuilder / barcode)
Force GCC to compile 32-bit programs on 64 bit platform
JS function algorithm interview case
Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution
112 stucked keyboard (20 points)
乾元通多卡聚合路由器的技术解析
联想R7000显卡的拆卸与安装
1107 social clusters (30 points)
Sprintf formatter abnormal exit problem
1115 counting nodes in a BST (30 points)
Wechat applet distance and map
JS scope
Common interview questions of microservice
Redis 入门和数据类型讲解
Rust基础入门之(基本类型)
Based on RFC 3986 (unified resource descriptor (URI): general syntax)
