package com.cdzy.common.model; import com.cdzy.common.enums.Code; import com.cdzy.common.enums.Message; import lombok.Data; import java.io.Serializable; /** * @param 响应数据的类型 * @author : attiya * 响应结果类 */ @Data public class JsonResult implements Serializable { /** * 状态码 */ private Integer code; /** * 状态描述信息 */ private String message; /** * 数据 */ private E data; public JsonResult() { } public JsonResult(Integer code, String message, E data) { super(); this.code = code; this.message = message; this.data = data; } @Override public String toString() { return "{" + "code=" + code + ", message='" + message + '\'' + ", data=" + data + '}'; } public static JsonResult success (Object data) { return new JsonResult<>(Code.SUCCESS, Message.SUCCESS,data); } public static JsonResult success (String msg) { return new JsonResult<>(Code.SUCCESS, msg,null); } public static JsonResult success (String msg,Object data) { return new JsonResult<>(Code.SUCCESS, msg, data); } public static JsonResult success () { return new JsonResult(Code.SUCCESS, Message.SUCCESS,null); } public static JsonResult failed() { return new JsonResult(Code.FAILED, Message.FAILED,null); } public static JsonResult failed(String msg) { return new JsonResult(Code.FAILED, msg,null); } public static JsonResult failed(String msg, Object data) { return new JsonResult<>(Code.FAILED, msg, data); } }