Response 接口统一返回实体类
根据实际情况修改文章来源地址https://www.toymoban.com/news/detail-578435.html
import java.io.Serializable;
/**
* @desc 统一结果返回实体类
* @author llp
* @date 2023/07/18 12:09
*/
public class Response implements Serializable {
/** 响应状态码 */
private Integer code;
/** 响应状态值 */
private final String status;
/** 响应消息 */
private final String message;
/** 响应数据 */
private final Object data;
/** 时间 */
private LocalDateTime time;
public Response(Integer code, String status, String message, Object data) {
this.code = code;
this.status = status;
this.message = message;
this.data = data;
}
public Response(String status, String message, Object data) {
this.status = status;
this.message = message;
this.data = data;
}
public static Response ok(Integer code, String status, String message, Object data){
return new Response(code, status, message, data);
}
public static Response ok(String status, String message, Object data){
return new Response(200, status, message, data);
}
public static Response ok(String status, String message){
return new Response(200, status, message, null);
}
public static Response ok(String status, Object data){
return new Response(200, status, "", data);
}
public static Response ok(String status){
return new Response(200, status, "", null);
}
public static Response error(Integer code, String status, String message, Object data){
return new Response(code, status, message, data);
}
public static Response error(String status, String message, Object data){
return new Response(status, message, data);
}
public static Response error(String status, String message){
return new Response(status, message, null);
}
public static Response error(String status, Object data){
return new Response(status, "", data);
}
public static Response error(String status){
return new Response(status, "", null);
}
@Override
public String toString() {
return "Response{" +
"code=" + code +
", status='" + status + '\'' +
", message='" + message + '\'' +
", data=" + data +
'}';
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getStatus() {
return status;
}
public String getMessage() {
return message;
}
public Object getData() {
return data;
}
}
文章来源:https://www.toymoban.com/news/detail-578435.html
到了这里,关于Response 接口统一返回实体类的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!