com.suchtool.nicecommon.core.entity.ResultWrapper Maven / Gradle / Ivy
package com.suchtool.nicecommon.core.entity;
import com.suchtool.nicecommon.core.constant.ResultCode;
import lombok.Data;
@Data
public class ResultWrapper {
private Boolean success = true;
private Integer code;
private T data;
private String message;
private ResultWrapper() {
}
public static ResultWrapper success() {
return success(null);
}
public static ResultWrapper success(T data) {
return assemble(ResultCode.SUCCESS.getCode(), true, data);
}
public static ResultWrapper error() {
return error(null);
}
public static ResultWrapper error(T data) {
return assemble(ResultCode.BUSINESS_FAIL.getCode(), false, data);
}
public ResultWrapper data(T data) {
this.setData(data);
return this;
}
public ResultWrapper message(String message) {
this.setMessage(message);
return this;
}
public ResultWrapper code(int code) {
this.setCode(code);
return this;
}
public static ResultWrapper assemble(int code, boolean success, T data) {
ResultWrapper resultWrapper = new ResultWrapper<>();
resultWrapper.setCode(code);
resultWrapper.setSuccess(success);
resultWrapper.setData(data);
return resultWrapper;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy