1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data;
import java.io.Serializable;
/** * todo JsonInclude 注解忽略 null值 看业务需求添加 */ @ApiModel("分页响应参数") @JsonInclude(value = JsonInclude.Include.NON_EMPTY) @Data public class JsonResult<T> implements Serializable { private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "结果状态", example = "200") private Integer code = 200; @ApiModelProperty(value = "结果数据") private T data; @ApiModelProperty(value = "结果描述", example = "成功") private String message = "ok";
public JsonResult() { }
public JsonResult(Integer code) { this(); this.code = code; }
public JsonResult(Integer code, T data) { this(code); this.data = data; }
public JsonResult(Integer code, String message) { this(code); this.message = message; }
public JsonResult(Integer code, String message, T data) { this(code, message); this.data = data; }
public static <T> JsonResult<T> success() { return new JsonResult(200); }
public static <T> JsonResult<T> success(T data) { return new JsonResult(200, data); }
public static <T> JsonResult<T> success(String message, T data) { return new JsonResult(200, message, data); }
public static <T> JsonResult<T> success(Integer code, String message, T data) { return new JsonResult(code, message, data); }
public static JsonResult<String> error() { return new JsonResult(500); }
public static <T> JsonResult<T> error(String message) { return new JsonResult(500, message); }
public static <T> JsonResult<T> error(Integer code, String message) { return new JsonResult(code, message); }
public static <T> JsonResult<T> error(Integer code, String message, T data) { return new JsonResult(code, message, data); }
}
|