Mysql paging processing (PageHelper)

Doing paging processing for the first time (I don't know what paging processing is going to do at all?)

Understanding: In fact, the front page passes different parameters {1. query conditions. 2. Query the number of pages (pageNum), 3 the number of pieces displayed on each page (pageSize)}, and then we (only do the data processing in the background (it is OK to display the correct data in the foreground), regardless of whether the front desk takes these data dry wool)

[
  {
    "id": 64,
    "name": "fdsaf"
  }
]

The format I use is the postman get test (this is the format anyway)

  

.No matter what sql query you do, first query all the data that the front desk may need in the xxxx visualization tool (if you can't use the command window, you can only say "the old driver takes me"), (actually It is to write a big idea, and then make a series of modified sql statements, which is more convenient for me)

  Note:

1
<if test="name != null and name != '' ">
AND name LIKE '%${name}%'
</if>
  (转)

    1. String concatenation in sql

         SELECT * FROM tableName WHERE name LIKE CONCAT(CONCAT('%', #{text}), '%');

    2. Use ${...} instead of #{...}

         SELECT * FROM tableName WHERE name LIKE '%${text}%';   

 (The sql statement of Ma Dan was originally written like this. It took me a long time to debug it because the company's direct fuzzy query was '%'+{name}+'%', but it didn't work. I used the second one directly)

2 The fields that need to be queried for the interface queried in the mapper.java file must be @Parem("xxx") otherwise you know
  
  List<Category> findAll(@Param("name") String name)throws Exception; 

PageHelper uses:

PageHelper.startPage(currenPage,pageSize); -----> These are the PageHelper  passed from the front desk that   can be used directly
 
 
  List<Category> list = categoryMapper.findAll(name); 

  list is to return the desired result

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325685700&siteId=291194637