@Data @NoArgsConstructor @AllArgsConstructor @Builder @ApiModel(value = "请求结果响应体") public class ResponseDataimplements Serializable{ @ApiModelProperty(value = "是否成功") private Boolean success; @ApiModelProperty(value = "响应状态回执码") private Integer code; @ApiModelProperty(value = "响应回执消息") private String msg; @ApiModelProperty(value = "数据体") private T data; @ApiModelProperty(value = "响应时间戳") private final long timestamps = System.currentTimeMillis(); public ResponseData(Boolean success, Integer code, String message) { super(); this.success = success; this.code = code; this.msg = message; } public static ResponseData ok(ResponseCode responseCode) { return new ResponseData(true,responseCode.code,responseCode.msg); } public static ResponseData ok(ResponseCode responseCode,Object data) { return new ResponseData(true,responseCode.code,responseCode.msg,data); } public static ResponseData ok(ResponseCode responseCode,String message,Object data) { return new ResponseData(true,responseCode.code,message,data); } public static ResponseData fail(ResponseCode responseCode) { return new ResponseData(false,responseCode.code,responseCode.msg); } public static ResponseData fail(ResponseCode responseCode,String message) { return new ResponseData(false,responseCode.code,message); } }
import java.util.HashMap; import static java.util.Objects.isNull; public class AjaxResult extends HashMap{ private static final long serialVersionUID = 1L; private static final String CODE_TAG = "code"; private static final String MSG_TAG = "msg"; private static final String DATA_TAG = "data"; public AjaxResult() { } public AjaxResult(int code,String msg){ super.put("code",code); super.put("msg",msg); } public AjaxResult(int code, String msg, Object data){ super.put("code",code); super.put("msg",msg); if(isNotNull(data)){ super.put("data", data); } } // 操作成功 public static AjaxResult success(){ return success("操作成功"); } public static AjaxResult success(Object data){ return success("操作成功",data); } public static AjaxResult success(String msg){ return success(msg,null); } public static AjaxResult success(String msg, Object data){ return new AjaxResult(200,msg,data); } // 操作失败 public static AjaxResult error(){ return error("操作失败"); } public static AjaxResult error(String msg){ return error(msg,null); } public static AjaxResult error(Object data){ return error("操作失败",data); } public static AjaxResult error(String msg, Object data){ return new AjaxResult(500,msg,data); } public boolean isNotNull(Object data){ return !isNull(data); } }



