io.afu.utils.common.dto.BaseRespDto Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of utils Show documentation
Show all versions of utils Show documentation
RffanLAB Utils For Many Way use
package io.afu.utils.common.dto;
import io.afu.utils.common.constant.CodeConstant;
import io.afu.utils.common.constant.ConstantEnum;
import io.afu.utils.common.constant.MsgConstant;
import io.afu.utils.exception.BaseException;
import java.util.List;
/**
* @author RffanLAB.方露宇
*/
public class BaseRespDto {
private Boolean status;
private Integer code;
private String msg;
private T data;
public Boolean getStatus() {
return status;
}
public void setStatus(Boolean status) {
this.status = status;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
this.status = true;
this.code = CodeConstant.OPERATION_SUCCESS;
this.msg = MsgConstant.OPERATION_SUCCESS;
return data;
}
public void setData(T data) {
this.status = true;
this.code = CodeConstant.OPERATION_SUCCESS;
this.msg = MsgConstant.OPERATION_SUCCESS;
this.data = data;
}
public void setTrue(){
this.status = true;
this.code = ConstantEnum.OPERATION_SUCCESS.getCode();
}
public void setFalse(){
this.status = false;
this.code = ConstantEnum.OPERATION_FAILED.getCode();
}
public void setTrueMsg(String msg){
this.status = true;
this.code = ConstantEnum.OPERATION_SUCCESS.getCode();
this.msg = msg;
}
public void setErrorMsg(String msg){
this.status = false;
this.code = ConstantEnum.OPERATION_FAILED.getCode();
this.msg = msg;
}
public void setTrue(ConstantEnum constantEnum){
this.status = true;
this.code = constantEnum.getCode();
this.msg = constantEnum.getMsg();
}
public void setFalse(ConstantEnum constantEnum){
this.status = false;
this.code = constantEnum.getCode();
this.msg = constantEnum.getMsg();
}
public void setFalse(BaseException e){
this.status = false;
this.code = e.getCode();
this.msg = e.getMessage();
}
/**
* 添加自定义fail方法
* @param msg 消息
* @param code 代码
* @return 返回实体类
*/
public static BaseRespDto fail(String msg,Integer code){
BaseRespDto baseRespDto = new BaseRespDto<>();
baseRespDto.setStatus(false);
baseRespDto.setCode(code);
baseRespDto.setMsg(msg);
return baseRespDto;
}
public static BaseRespDto fail(BaseException e){
BaseRespDto baseRespDto = new BaseRespDto<>();
baseRespDto.setStatus(false);
baseRespDto.setCode(e.getCode());
baseRespDto.setMsg(e.getMessage());
return baseRespDto;
}
public static BaseRespDto fail(String msg) {
BaseRespDto baseRespDto = new BaseRespDto<>();
baseRespDto.setStatus(false);
baseRespDto.setCode(-1);
baseRespDto.setMsg(msg);
return baseRespDto;
}
public static BaseRespDto fail(ConstantEnum constantEnum){
BaseRespDto baseRespDto = new BaseRespDto<>();
baseRespDto.setStatus(false);
baseRespDto.setCode(constantEnum.getCode());
baseRespDto.setMsg(constantEnum.getMsg());
return baseRespDto;
}
public static BaseRespDto fail(Object o){
BaseRespDto