1、狀態碼枚舉類
package com.donleo.ssm.utils; /** * @author liangd * date 2020-11-22 16:51 * code */ public enum ResponseLayCode { //成功狀態碼 SUCCESS(0), //空值狀態碼 NULL(1); private int code; ResponseLayCode(int code) { this.code = code; } public int getCode() { return code; } public void setCode(int code) { this.code = code; } }
2、返回格式封裝類
package com.donleo.ssm.utils; /** * @author liangd * date 2020-11-22 16:41 * code LayUI 返回格式數據工具類 */ public class ResponseLayResult<T> { /** * 返回狀態碼 */ private int code; /** * 總條數 */ private long count; /** * 提示信息 */ private String msg; /** * 返回數據 */ private T data; /** * 有數據構造方法 */ private ResponseLayResult(int code, long count, T data) { this.code = code; this.count = count; this.data = data; } /** * 空值構造方法 */ private ResponseLayResult(int code, long count, String msg) { this.code = code; this.count = count; this.msg = msg; } /** * getter/setter 方法 */ public int getCode() { return code; } public void setCode(int code) { this.code = code; } public long getCount() { return count; } public void setCount(long 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; } /** * 返回有數據信息 */ public static <T> ResponseLayResult<T> createBySuccess(long count, T data) { return new ResponseLayResult<T>(ResponseLayCode.SUCCESS.getCode(), count, data); } /** * 返回空數據信息 */ public static <T> ResponseLayResult<T> createByNull(long count, String msg) { return new ResponseLayResult<T>(ResponseLayCode.NULL.getCode(), count, msg); } /** * 返回空數據信息(count為null) */ public static <T> ResponseLayResult<T> createByNull(String msg) { return new ResponseLayResult<T>(ResponseLayCode.NULL.getCode(), ResponseLayCode.SUCCESS.getCode(), msg); } }