1.Object
@ToString
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class R<T> implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("状态码,0:成功,1:失败")
private int code;
@ApiModelProperty("返回信息")
private String msg;
@ApiModelProperty("返回数据")
private T data;
public static R ok(Object data) {
return new R(ResponseConstants.SUCCESS,"success",data);
}
public static R ok(int code, String msg, Object data) {
return new R().setStatus(code).setMsg(msg).setData(data);
}
public static R fail(Object data) {
return new R(ResponseConstants.FAIL, "error",data);
}
public static R fail(int code, String msg, Object data) {
return new R().setStatus(code).setMsg(msg).setData(data);
}
}
2.范型T
@ToString
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class R<T> implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("状态码,0:成功,1:失败")
private int code;
@ApiModelProperty("返回信息")
private String msg;
@ApiModelProperty("返回数据")
private T data;
public static <T> R<T> ok(T data) {
return new R(ResponseConstants.SUCCESS, "", data);
}
public static <T> R<T> ok(Integer code, String msg, T data) {
return new R(code, msg, data);
}
public static <T> R<T> fail(T data) {
return new R(ResponseConstants.FAIL, "", data);
}
public static <T> R<T> fail(Integer code, String msg, T data) {
return new R(code, msg, data);
}
}