通用响应类分享

---转载请标注出处 

/**
* @Author : liuzhiyuan
* @Create : 2024/1/11
* Description : 响应封装
*/
@Data
@ToString
public class ResponseBean<T> implements Serializable {
private static final long serialVersionUID = 1L;
private long timestamp;
private String statusText;
private String message;
private T data;

public ResponseBean(T data) {
this.data = data;
}
public ResponseBean(String statusText) {
this.statusText = statusText;
}
public ResponseBean() {}


public static <T> ResponseBean<T> success(){
ResponseBean<T> t = new ResponseBean<>();
t.setStatusText(SystemConfig.SUCCESS);
t.setTimestamp(SystemConfig.getTimeNOFormat());
return t;
}
public static <T> ResponseBean<T> success(T data){
ResponseBean<T> t = new ResponseBean<>(data);
t.setStatusText(SystemConfig.SUCCESS);
t.setTimestamp(SystemConfig.getTimeNOFormat());
return t;
}
public static <T> ResponseBean<T> success(String message){
ResponseBean<T> t = new ResponseBean<>();
t.setStatusText(SystemConfig.SUCCESS);
t.setMessage(message);
t.setTimestamp(SystemConfig.getTimeNOFormat());
return t;
}
public static <T> ResponseBean<T> success(T data,String message){
ResponseBean<T> t = new ResponseBean<>(data);
t.setStatusText(SystemConfig.SUCCESS);
t.setTimestamp(SystemConfig.getTimeNOFormat());
t.setMessage(message);
return t;
}
public static <T> ResponseBean<T> fail(){
ResponseBean<T> t = new ResponseBean<>();
t.setStatusText(SystemConfig.FAIL);
t.setTimestamp(SystemConfig.getTimeNOFormat());
return t;
}
public static <T> ResponseBean<T> fail(T data){
ResponseBean<T> t = new ResponseBean<>(data);
t.setStatusText(SystemConfig.FAIL);
t.setTimestamp(SystemConfig.getTimeNOFormat());
return t;
}
public static <T> ResponseBean<T> fail(String message){
ResponseBean<T> t = new ResponseBean<>();
t.setStatusText(SystemConfig.FAIL);
t.setMessage(message);
t.setTimestamp(SystemConfig.getTimeNOFormat());
return t;
}
public static <T> ResponseBean<T> fail(T data,String message){
ResponseBean<T> t = new ResponseBean<>(data);
t.setStatusText(SystemConfig.FAIL);
t.setTimestamp(SystemConfig.getTimeNOFormat());
t.setMessage(message);
return t;
}
}
posted @ 2024-03-11 16:30  牛啊!  阅读(5)  评论(0编辑  收藏  举报