Skip to content

Instantly share code, notes, and snippets.

@keepingcoding
Last active January 8, 2020 07:46
Show Gist options
  • Save keepingcoding/c6798e737119f9bc87a2f6c13b6b4222 to your computer and use it in GitHub Desktop.
Save keepingcoding/c6798e737119f9bc87a2f6c13b6b4222 to your computer and use it in GitHub Desktop.
通用返回bean
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
@Getter
@Setter
@Accessors(chain = true)
public class BaseResponse<T> implements Serializable {
/** 状态 **/
private boolean success = true;
/** 状态码 **/
private String resultCode = "200";
/** 状态描述 **/
private String resultMsg = "ok";
/** 业务模型对象 **/
private T result;
/** 参数校验错误列表 **/
private Map<String, List<String>> validationErrors;
/** 耗费时间 **/
private long costTime;
public BaseResponse() {
}
public BaseResponse(T result) {
this.result = result;
}
public BaseResponse(boolean success, String resultCode, String resultMsg, T result) {
this.success = success;
this.resultCode = resultCode;
this.resultMsg = resultMsg;
this.result = result;
}
public BaseResponse(Map<String, List<String>> validationErrors) {
this.success = false;
this.resultCode = "501";
this.resultMsg = "参数验证错误";
this.validationErrors = validationErrors;
}
public long calcCostTime(long beginTime) {
costTime = System.currentTimeMillis() - beginTime;
return costTime;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment