Springbootとlayui統合pageHelperページングプラグイン


@[email protected]
ここでspringboot+pagehelper統合を記録するにはまずpom.xmlインポート依存
// An highlighted block
<!--pagehelper     -->
      <dependency>
          <groupId>com.github.pagehelper</groupId>
          <artifactId>pagehelper</artifactId>
          <version>5.1.8</version>
      </dependency>

      <dependency>
          <groupId>com.github.pagehelper</groupId>
          <artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
          <version>1.2.5</version>
      </dependency>

      <dependency>
          <groupId>com.github.pagehelper</groupId>
          <artifactId>pagehelper-spring-boot-starter</artifactId>
          <version>1.2.5</version>
      </dependency>

ここでは3つの依存をインポートする必要があります.そうしないと、ページングに問題が発生する可能性があります(すべてのデータがクエリーされます)、サービスでページング処理を行うことが望ましいです.
/**
  *       ,  
  * @param user
  * @param pageSize     
  * @param pageNum    
  * @return
  */
 public templetJson loadList(user user , Integer pageSize, Integer pageNum){
     templetJson tem=null;
     try{
     	//     
         Page<user> page = PageHelper.startPage(pageNum, pageSize);
         //      
         List list= userMapper.loadUserList(user);
         //  list    
         PageInfo  pageInfo = new PageInfo(list);
         //      (      )
         tem=utils.loadJsonPage(pageInfo);
     }catch (Exception e){
         e.printStackTrace();
     }
    return tem;
 }

loadJsonPage()メソッドlayuiページングで使用するメソッドの処理
  /**
  *       
  * @param pageInfo
  * @return
  */
 public static templetJson loadJsonPage(PageInfo pageInfo){
     templetJson templetJson = new templetJson();
     if(pageInfo!=null){

     }
     try{
         List list= pageInfo.getList();
         int i=(int)pageInfo.getTotal();
         templetJson.setCount(i);
         templetJson.setCode(0);
         templetJson.setMsg("");
         templetJson.setData(list);
     }catch (Exception e){
         templetJson.setCode(1);
     }
     return templetJson;
 }


templetJson bean
package com.example.manage.bean;

/**
* layui      bean
*/
public class templetJson {
 private Integer code;
 private String msg;
 private Integer count;
 private Object data;

 public Integer getCode() {
     return code;
 }

 public void setCode(Integer code) {
     this.code = code;
 }

 public String getMsg() {
     return msg;
 }

 public void setMsg(String msg) {
     this.msg = msg;
 }

 public Integer getCount() {
     return count;
 }

 public void setCount(Integer count) {
     this.count = count;
 }

 public Object getData() {
     return data;
 }

 public void setData(Object data) {
     this.data = data;
 }
}