当前位置:网站首页>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
边栏推荐
- Technical analysis of qianyuantong multi card aggregation router
- Pan details of deep learning
- Go practice -- gorilla/rpc (gorilla/rpc/json) used by gorilla web Toolkit
- leetcode406. Rebuild the queue based on height
- Wechat applet distance and map
- leetcode435. Non overlapping interval
- 2022-02-12 daily clock in: problem fine brush
- [research materials] 2021 China's game industry brand report - Download attached
- Common methods of JS array
- Make your own dataset
猜你喜欢

Audio Focus Series: write a demo to understand audio focus and audiomananger

Celebrate the new year together
![[batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)](/img/ce/d6f4fb30727e7436b6443537429ad4.png)
[batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)

(subplots用法)matplotlib如何绘制多个子图(轴域)

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

Three representations of signed numbers: original code, inverse code and complement code

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

The consumption of Internet of things users is only 76 cents, and the price has become the biggest obstacle to the promotion of 5g industrial interconnection

Oracle SQL table data loss
![[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)](/img/8b/c10423ee95200a0d94f9fb9dde76eb.jpg)
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
随机推荐
XML配置文件
Realize file download through the tag of < a > and customize the file name
appium1.22.x 版本後的 appium inspector 需單獨安裝
1118 birds in forest (25 points)
Redis 过期淘汰机制
Burp suite plug-in based on actual combat uses tips
Self introduction and objectives
Go practice - gorilla / handlers used by gorilla web Toolkit
RT thread flow notes I startup, schedule, thread
Go practice -- use redis in golang (redis and go redis / redis)
JS dynamic table creation
Go practice -- generate and read QR codes in golang (skip2 / go QRcode and boombuilder / barcode)
112 stucked keyboard (20 points)
最大连续子段和(动态规划,递归,递推)
Interview question -- output the same characters in two character arrays
SSM framework integration
XML Configuration File
Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément
Pan details of deep learning
Redis 入門和數據類型講解
