当前位置:网站首页>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
边栏推荐
- Yolov5 input (I) -- mosaic data enhancement | CSDN creative punch in
- Pan details of deep learning
- Sprintf formatter abnormal exit problem
- 112 stucked keyboard (20 points)
- Actual combat 8051 drives 8-bit nixie tube
- Self introduction and objectives
- study hard and make progress every day
- 1110 complete binary tree (25 points)
- Notes | numpy-07 Slice and index
- leetcode406. Rebuild the queue based on height
猜你喜欢

Principles of BTC cryptography

leetcode406. Rebuild the queue based on height

Burp suite plug-in based on actual combat uses tips

Handler understands the record

Make your own dataset

Webrtc M96 release notes (SDP abolishes Plan B and supports opus red redundant coding)

【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)
![[set theory] relationship properties (common relationship properties | relationship properties examples | relationship operation properties)](/img/af/8dfa783c87363a9d75c52e7680d508.jpg)
[set theory] relationship properties (common relationship properties | relationship properties examples | relationship operation properties)

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

JS dynamic table creation
随机推荐
Redis Introduction et explication des types de données
sql语句模糊查询遇到的问题
leetcode860. Lemonade change
Make your own dataset
Online VR model display - 3D visual display solution
[research materials] 2022q1 game preferred casual game distribution circular - Download attached
1086 tree traversals again (25 points)
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
Notes | numpy-08 Advanced index
Shuttle + alluxio accelerated memory shuffle take-off
Redis breakdown penetration avalanche
[research materials] annual report of China's pension market in 2021 - Download attached
Go practice -- use redis in golang (redis and go redis / redis)
【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)
[develop wechat applet local storage with uni app]
appium1.22.x 版本後的 appium inspector 需單獨安裝
study hard and make progress every day
leetcode435. Non overlapping interval
RT thread flow notes I startup, schedule, thread
Redis 入門和數據類型講解
