ResultCode 类
public class ResultCode {
public static Integer SUCCESS = 200;
public static Integer ERROR = 500;
public static Integer FORBIDDEN = 403;
public static Integer UNAUTHORIZED = 401;}
Result 类
@Data //lombok 注解 public class Result {
// 返回码
private Integer code;
// 返回消息
private String message;
// 返回数据
private Map
public Result(){跟单网https://www.gendan5.com/}
public Result message(String message){
this.setMessage(message);
return this;
public Result code(Integer code){
this.setCode(code);
return this;
public Result data(String key, Object value){
this.data.put(key, value);
return this;
}public Result data(Map
this.setData(map);
return this;
使用示例
@RequestMapping("/get")
public Result get(){
HashMap map = new HashMap();
map.put("username","admin");
map.put("password","123456");
Result r = new Result();
r.code(ResultCode.SUCCESS).message(" 成功访问 ").data(map);
return r;