controller父类:
/**
* Controller 父类
*/
public class BaseController {
//请求处理成功,返回业务数据
protected RespResult returnSuccess(Object data) {
RespResult respResult = new RespResult();
respResult.setCode(RespResult.Code.SUCCESS.getValue());
respResult.setData(data);
return respResult;
}
/**
* 方法重载 可以传信息
*/
//请求处理成功,返回业务数据
RespResult returnSuccess(Object data,String message) {
RespResult respResult = new RespResult();
respResult.setCode(RespResult.Code.SUCCESS.getValue());
respResult.setData(data);
respResult.setMessage(message);
return respResult;
}
//请求处理失败,返回提示信息
RespResult returnFailed(String message) {
RespResult respResult = new RespResult();
respResult.setCode(RespResult.Code.FAILED.getValue());
respResult.setMessage(message);
return respResult;
}
}
VO:
@Data
@Component
public class RespResult<T> {
//业务处理状态0:成功,其它:失败
private int code=Code.SUCCESS.getValue();
//提示信息(错误或者异常提示用户信息)
private String message;
//业务返回数据
private T data;
/**
* 业务处理状态枚举
*/
public enum Code {
SUCCESS(200), FAILED(404);
private int value;
Code(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
}