Commit 7a001bed authored by wujipeng's avatar wujipeng
Browse files

响应体优化

parent e6351ce8
...@@ -2,41 +2,35 @@ package com.ruzhoukj.knowledgegraph.result; ...@@ -2,41 +2,35 @@ package com.ruzhoukj.knowledgegraph.result;
public class Response<T> { public class Response<T> {
private boolean success; private Integer code;
private String message; private String message;
private T data; private T data;
private Integer total;
public Response() { public Response() {
} }
public Response(boolean success, String message, T data) { public Response(Integer code, String message, T data) {
this.success = success; this.code = code;
this.message = message; this.message = message;
this.data = data; this.data = data;
} }
public static <T> Response<T> success(T data) { public static <T> Response<T> success(T data) {
return new Response<>(true, "操作成功", data); return new Response<>(200, "操作成功", data);
} }
public static <T> Response<T> success(T data, int total) {
Response<T> response = new Response<>(true, "操作成功", data);
response.setTotal(total);
return response;
}
public static <T> Response error(String message) { public static <T> Response error(String message) {
return new Response<>(false, message, null); return new Response<>(400, message, null);
} }
// Getters and Setters // Getters and Setters
public boolean isSuccess() { public Integer getCode() {
return success; return code;
} }
public void setSuccess(boolean success) { public void setCode(Integer code) {
this.success = success; this.code = code;
} }
public String getMessage() { public String getMessage() {
...@@ -55,11 +49,5 @@ public class Response<T> { ...@@ -55,11 +49,5 @@ public class Response<T> {
this.data = data; this.data = data;
} }
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment