当前位置:网站首页>52: Chapter 5: developing admin management services: 5: developing [paging query admin account list, interface]; (swagger's @apiparam(), annotate the method parameters; PageHelper paging plug-in; Inte
52: Chapter 5: developing admin management services: 5: developing [paging query admin account list, interface]; (swagger's @apiparam(), annotate the method parameters; PageHelper paging plug-in; Inte
2022-07-27 13:24:00 【Small withered forest】
explain :
(1) The content of this blog : Development 【 Paging query admin Account list , Interface 】;
Catalog
One : Rationality of this blog ;
One : Rationality of this blog ;
then , This blog , Is to develop 【 Inquire about admin Account list , Interface 】
Two : Formal development ;
1. stay 【api】 Interface Engineering AdminMngControllerApi Interface , Definition 【 Paging query admin Account list , Interface 】;
/** * 【 Paging query admin Account list , Interface 】; * * @param page: Which page do you want to query ; * @param pageSize: Number of entries per page ; * @return */ @ApiOperation(value = " Inquire about admin list ", notes = " Inquire about admin list ", httpMethod = "POST") @PostMapping("/getAdminList") // Set the routing , This needs to be agreed between the front and back ; public GraceJSONResult getAdminList(@RequestParam @ApiParam(name = "page", value = " Which page do you want to query ", required = false) Integer page, @RequestParam @ApiParam(name = "pageSize", value = " Number of entries per page ", required = false) Integer pageSize);explain :
(1) This interface's url、 Request mode 、 Parameters , It's not nonsense , The front and rear ends should be consistent ;
(2) here , Using the Swagger Of @ApiParam(), To set the parameters in the method , Annotate ;
2. stay 【admin】 Managed services AdminMngController Class , To achieve 【 Paging query admin Account list , Interface 】;
/** * 【 Paging query admin Account list , Interface 】; * * @param page: Which page do you want to query ; * @param pageSize: Number of entries per page ; * @return */ @Override public GraceJSONResult getAdminList(Integer page, Integer pageSize) { // If the front end requests this interface , No transmission page Parameters ; Then we will give it a default value 1; if (page == null) { page = COMMON_START_PAGE; } // If the front end requests this interface , No transmission pageSize Parameters ; Then we will give it a default value 10; if (pageSize == null) { pageSize = COMMON_PAGE_SIZE; } // call service Layer logic , To query paging data ; PagedGridResult result = adminUserService.queryAdminList(page, pageSize); return GraceJSONResult.ok(result); }explain :
(1) Here we judge page and pageSize Two parameters ; If the front end does not transmit , Take the default value ;
(2)PageHelper Paging plug-ins have been heavily used by themselves before ; of PageHelper Contents of paging plug-in , If necessary , You can refer to 【 additional :PageHelper Paging plug-in's :Page and PageInfo The difference between ;】、【Spring Boot E-commerce projects 40: Commodity module 6 : Backstage 【 List of goods 】 Interface ;( Thought of a question :【PageHelper When paging query , In any case, you must first find out all the data 】: Isn't that a waste ?PS: Wrong understanding )】 And so on ;
(3) then , call Service Logic written by layer , Paging query data , And assemble it into paging objects that meet the requirements of the front end ;
● here , We are 【common】 In general engineering , Created PagedGridResult class ; We are based on this class , To assemble paging objects ;
package com.imooc.utils; import java.util.List; /** * * @Title: PagedGridResult.java * @Package com.imooc.utils * @Description: Used to return paging Grid Data format * Copyright: Copyright (c) 2019 */ public class PagedGridResult { private int page; // What page is it now private long total; // Total number of pages private long records; // Total number of records private List<?> rows; // What is displayed on each line , That is, the data in the current page ; public int getPage() { return page; } public void setPage(int page) { this.page = page; } public long getTotal() { return total; } public void setTotal(long total) { this.total = total; } public void setTotal(int total) { this.total = total; } public long getRecords() { return records; } public void setRecords(long records) { this.records = records; } public List<?> getRows() { return rows; } public void setRows(List<?> rows) { this.rows = rows; } }● The reason why we , No direct use PageHelper Provided Page Object or PageInfo object , As a " The back end returns to the paging object of the front end ", It's about creating PagedGridResult, As a " The back end returns to the paging object of the front end "; The main reason is , The back end returns to the paging object of the front end , It needs to meet the requirements of the front end ;
● Be reasonable , I didn't take a close look at the content of the front end here ; The agreement between the front end and the back end , I didn't make it myself ; There is no clear interface document ; therefore , There is no need to spend energy here for the time being , Thoroughly understand everything ;
● Just need to know 【 We created PagedGridResult object ; then , When we page , according to PagedGridResult Assemble paging objects in the specified format , And then it goes back to the front end , It is in line with the agreement between the front and back , Namely OK Of ;】,( For now ) That's enough ;
3. stay 【admin】 Managed services AdminUserService Interface , Define an implementation 【 Paging query admin Account list , Interface 】;
/** * Paging query ,admin_user Admin list * @param page: Which page do you want to query ; * @param pageSize * @return */ public PagedGridResult queryAdminList(Integer page, Integer pageSize);explain :
(1)service This method of layer , The return value type is PagedGridResult Paging object ;
4. stay 【admin】 Managed services AdminUserServiceImpl In the implementation class , To achieve 【 Paging query admin Account list , Interface 】;
/** * Paging query ,admin_user Admin list * @param page: Which page do you want to query ; * @param pageSize * @return */ @Override public PagedGridResult queryAdminList(Integer page, Integer pageSize) { // 1. Open paging PageHelper.startPage(page, pageSize); // 2. utilize tkmybatis Of Example, User defined query criteria ; Use the paging information set above , Go to query admin_user surface ; // 2.1 First create a query instance , The instance , Is aimed at AdminUser Inquiring ; Example adminExample = new Example(AdminUser.class); //Example You can set no query conditions ; meanwhile , You can also add some parameters ; such as , Here we arrange them in reverse order of creation time ; adminExample.orderBy("createdTime").desc(); // Here we are : Without any conditions , Go to query admin_user surface ; let me put it another way ,( If we're not here 1 If paging information is set in ) // We just want to inquire admin_user All the contents of the table ; List<AdminUser> adminUserList = adminUserMapper.selectByExample(adminExample); // 3. then , According to the requirements of the front end , Assemble a paging object that meets the requirements ; We , Here, according to the requirements of the front end , Created a // individual PagedGridResult object ; We will use this object , To assemble the paging object returned to the front end ; return setterPagedGrid(adminUserList, page); } /** * Tool method : According to the results of paging query database , Assemble into ( Meet the requirements of the front end ) Paging object ; * For our project , We created one PagedGridResult object ; This object , It can meet the requirements of the front end for paging data format ; * * @param adminUserList: According to the paging conditions , Query the database , Get the data of the current page ; * @param page: Which page do you want to query ; * @return */ private PagedGridResult setterPagedGrid(List<?> adminUserList, Integer page) { /** * utilize PageHelper Official PageInfo: According to the results of the paging query above , obtain PageInfo Paging object ; * This PageInfo Paging object , It will help us calculate a lot of information about paging ; */ PageInfo<?> pageInfo = new PageInfo<>(adminUserList); // establish PagedGridResult object , And assemble ; PagedGridResult pagedGridResult = new PagedGridResult(); pagedGridResult.setRows(adminUserList);// hold 【 Query the database according to paging conditions , Get the data of the current page ;】 Set it in ; pagedGridResult.setPage(page);// Set the current page pagedGridResult.setRecords(pageInfo.getTotal());// Todo adopt pageInfo, Get the total number of records ;( Through the measured , My writing here is reliable ) pagedGridResult.setTotal(pageInfo.getPages());// Todo adopt pageInfo, Get the total number of pages ; // return , Assembled PagedGridResult object ; return pagedGridResult; }explain :
(1) of PageHelper Paged content , You can refer to 【 additional :PageHelper Paging plug-in's :Page and PageInfo The difference between ;】 And so on ;
(2) We are 【model】 In model engineering , Has introduced PageHelper Rely on ;
、
(3) Code logic description ;
(4) That means , When the front and back end interact here , Processing of paging data , No selection PageHelper Provided off the shelf PageInfo or Page; It doesn't seem very elegant ?
(5) Code logic description : In the assembly PagedGridResult When paging objects , I still use PageHelper Provided PageInfo;
(6) Code logic description : according to PagedGridResult Definition of paging object , Assign values to its attributes ;( What we do here , Different from the course ; however , Through the measured , The practice in the course is wrong )
(7) The revision of the previous two blogs :
● stay 【Spring Boot E-commerce projects 40: Commodity module 6 : Backstage 【 List of goods 】 Interface ;( Thought of a question :【PageHelper When paging query , In any case, you must first find out all the data 】: Isn't that a waste ?PS: Unresolved )_ Xiao kulin's blog -CSDN Blog _springboot List of goods 】 Medium , This question , I think more ;
● stay 【 additional :PageHelper Paging plug-in's :Page and PageInfo The difference between ;】 in , There are many places where the description is not rigorous , A little adjustment ;
3、 ... and : effect ;
First, the whole situation install Look at the whole project ; then , Start the front-end project ; Remember to use SwitchHost Open virtual domain name mapping ; start-up 【admin】 The main startup class of the management service ;
Four :【 newly added admin account number , Interface 】、【 Paging query admin Account list , Interface 】, It also requires users to log in , Can be operated ;
Use us in 【50: The fifth chapter : Development admin management service :3: Development 【 Inquire about admin Does the user name already exist , Interface 】;( This interface can only be called when logging in ; So we wrote interceptors , Let it intercept the request , Determine whether the user is logged in ;)】 Created in the AdminTokenInterceptor Interceptor ; stay InterceptorConfig Class AdminTokenInterceptor Where the interceptor is , Add to 【 newly added admin account number , Interface 】、【 Paging query admin Account list , Interface 】 Interception of ;
边栏推荐
- Gartner authority predicts eight development trends of network security in the next four years
- Xposed+fdex2 app shelling (black cat complains about app shelling)
- Seata 在蚂蚁国际银行业务的落地实践
- Getting started for beginners: build your own blog with WordPress
- 湖仓一体电商项目背景与架构介绍及基础环境准备
- QT excellent open source project 13: qscintilla
- 实现新增加硬盘的磁盘分区和文件系统挂载
- Jesd204b debugging notes (practical version)
- Reptile
- SQL group by statement
猜你喜欢

Xposed+fdex2 app shelling (black cat complains about app shelling)

Open source project - taier1.2 release, new workflow, tenant binding simplification and other functions

Qt优秀开源项目之十三:QScintilla

程序员培训学习后好找工作吗

Eccv2022 | Ru & Google proposed to use clip for zero shot target detection!

文章复现:SRCNN

Distributed system architecture theory and components

Seata 在蚂蚁国际银行业务的落地实践

Have you understood these 30 questions of enabling financial risk control plus points

B站713故障后的多活容灾建设|TakinTalks大咖分享
随机推荐
[node+ts] build node+typescript project
二分法查询数组中的值
POJ1273 Drainage Ditches【最大流】【SAP】
Minimally invasive brain science broke the listing: the company's market value is HK $14.3 billion, and minimally invasive medical is the major shareholder
Feign's dynamic proxy
Is it easy to find a job after programmer training and learning
JS single thread understanding notes - Original
工具及方法 - 在线流程图描画
Go语言系列:如何搭建Go语言开发环境?
Zhongke Lanxun fell 30% on the first day of listing: Huang Zhiqiang, 60, started a company with a market value of 7.7 billion
Connotative quotations
Pat class B 1109 good at C (detailed)
Poj1273 drainage ditches [maximum flow] [SAP]
Open source project - taier1.2 release, new workflow, tenant binding simplification and other functions
Realize the disk partition and file system mount of the newly added hard disk
《数字经济 科技向善》大咖对谈干货来啦
POJ2446 Chessboard【二分图最大匹配】
xshell7可以登录mysql虚拟机不能登陆mysql
Final solution for high collapse (no side effects)
力扣 1480. 一维数组的动态和 383. 赎金信412. Fizz Buzz







、



