返回的utils
package com.springbootredis.redis.config;
import java.util.HashMap;
import java.util.Map;
public class R {
private Boolean success;
private Integer code;
private String message;
private HashMap<String,Object> data = new HashMap();
public static R success(){
return new R(ResultCode.SUCCESS.getSuccess(),ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage());
}
public static R failed(){
return new R(ResultCode.FAILED.getSuccess(),ResultCode.ERROR.getCode(),ResultCode.ERROR.getMessage());
}
public static R error(){
return new R(ResultCode.ERROR.getSuccess(),ResultCode.ERROR.getCode(),ResultCode.ERROR.getMessage());
}
public R data(HashMap<String,Object> map){
this.setData(map);
return this;
}
public R data(String key,String value){
this.data.put(key,value);
return this;
}
public R message(String message){
this.setMessage(message);
return this;
}
public R code(Integer code){
this.setCode(code);
return this;
}
public R success(Boolean success){
this.setSuccess(success);
return this;
}
public R(Boolean success, Integer code, String message) {
this.success = success;
this.code = code;
this.message = message;
}
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public HashMap<String, Object> getData() {
return data;
}
public void setData(HashMap<String, Object> data) {
this.data = data;
}
}
返回的枚举
package com.springbootredis.redis.config;
public enum ResultCode {
SUCCESS(true,2000,"成功"),
FAILED(false,4000,"失败"),
ERROR(false,5000,"未知错误");
private final Boolean success;
private final Integer code;
private final String message;
ResultCode(Boolean success, Integer code, String message) {
this.success = success;
this.code = code;
this.message = message;
}
public Boolean getSuccess() {
return success;
}
public Integer getCode() {
return code;
}
public String getMessage() {
return message;
}
}
|