layUI 返回 josn 数据列表封装工具类

package com.wlwq.workers.controller.utl;

import com.wlwq.workers.controller.enums.ResponseLayCode;
/**
  * 封装后端返回给LayUI的Json数据
 * @author EDZ
 *
 * @param
 */
public class ServerLayResponse {
        
    private int code;
    private long count;
    private String msg;
    private T data;
    
    
    
    
    /**
      *  结果非空构造方法(有数据构造方法)
     * @param code
     * @param count
     * @param data
     */
    public ServerLayResponse(int code, long count, T data) {
        super();
        this.code = code;
        this.count = count;
        this.data = data;
    }
    


    /**
      * 返回空值构造方法(无数据构造方法)
     * @param code
     * @param count
     * @param msg
     */
    public ServerLayResponse(int code, long count, String msg) {
        super();
        this.code = code;
        this.count = count;
        this.msg = msg;
    }


    /**
     * getter、setter方法
     * @return
     */
    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }
    public long getCount() {
        return count;
    }
    public void setCount(int count) {
        this.count = count;
    }
    public String getMsg() {
        return msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }
    public T getData() {
        return data;
    }
    public void setData(T data) {
        this.data = data;
    }
    
    
    /**
      * 返回有数据信息 
     * @param code
     * @param count
     * @param data
     * @return
     */
    public static ServerLayResponse createBySuccess(long count, T data){
        return new ServerLayResponse(ResponseLayCode.SUCCESS.getCode(),count,data);
    } 
    
    /**
      * 返回空数据信息
     * @param count
     * @param msg
     * @return
     */
    public static ServerLayResponse createByNull(long count, String msg){
        return new ServerLayResponse(ResponseLayCode.NULL.getCode(),count,msg);
    } 
    /**
     * 返回空数据信息(count为0)
     * @param msg
     * @return
     */
    public static ServerLayResponse createByNull(String msg){
        return new ServerLayResponse(ResponseLayCode.NULL.getCode(),ResponseLayCode.SUCCESS.getCode(),msg);
    } 
    
    
}
 

 

package com.wlwq.workers.controller.enums;

/**
 * LayUI 获取数据状态值
 * @author ZGZ
 *
 */
public enum ResponseLayCode {
    
    SUCCESS(0),
    NULL(1);
    
    private int code;

    private ResponseLayCode(int code) {
        this.code = code;
    }

    public int getCode() {
        return code;
    }

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

 

/**
     * 获取分页列表
     * @return
     */
    @RequestMapping("/findPageServiceOrder")
    @ResponseBody
    public ServerLayResponse>> findPageServiceOrder(ServiceOrderVo serviceOrderVo){        
        PageInfo> pageList= serviceOrderServiceImp.findPageServiceOrder(serviceOrderVo);
         if(pageList.getTotal()>0) {
             return ServerLayResponse.createBySuccess(pageList.getTotal(),pageList.getList());
        
         }else {             
             return ServerLayResponse.createByNull(pageList.getTotal(),"无数据");     
         }            
    }
    

 

 

 

 

 

 

 

 

你可能感兴趣的:(java)