当前位置:网站首页>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
边栏推荐
- 112 stucked keyboard (20 points)
- [basic grammar] Snake game written in C language
- Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
- Go practice -- design patterns in golang's singleton
- 【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)
- leetcode435. Non overlapping interval
- Burp suite plug-in based on actual combat uses tips
- Differences among bio, NiO and AIO
- 1115 counting nodes in a BST (30 points)
- (perfect solution) how to set the position of Matplotlib legend freely
猜你喜欢

Common interview questions of microservice

Promise

leetcode406. Rebuild the queue based on height

Introduction to deep learning (II) -- univariate linear regression

How to connect the network: Chapter 2 (Part 1): a life cycle of TCP connection | CSDN creation punch in

Kept hot standby and haproxy

Unity tool Luban learning notes 1

Why is go language particularly popular in China

Silent authorization login and registration of wechat applet

Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)
随机推荐
Go language interface learning notes
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
BTC-密码学原理
Messy change of mouse style in win system
Wechat applet distance and map
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
Bluebridge cup real topic 2020 palindrome date simulation construction provincial competition
[backtrader source code analysis 5] rewrite several time number conversion functions in utils with Python
JS dynamic table creation
Shallow and first code
BIO、NIO、AIO区别
JS scope
Actual combat 8051 drives 8-bit nixie tube
Gbase8s unique index and non unique index
Learn libcef together -- set cookies for your browser
Differences among bio, NiO and AIO
"Pthread.h" not found problem encountered in compiling GCC
Chapter II program design of circular structure
Go practice -- gorilla/rpc (gorilla/rpc/json) used by gorilla web Toolkit
Interface frequency limit access
