封装类
package com.chen.utils;
import java.util.HashMap;
import java.util.Map;
public class Rs extends HashMap<String,Object> {
public static Integer code ;
public static String msg;
public static Map data=new HashMap();
public Rs() {
super.put("code",this.code);
super.put("msg",this.msg);
super.put("data",this.data);
}
public Rs(Integer code,String msg){
this.code=code;
this.msg=msg;
super.put("code",code);
super.put("msg",msg);
}
@Override
public Rs put(String key, Object value) {
this.data.put(key,value);
return new Rs();
}
public static Rs OK(){
return new Rs(200,"成功");
}
public static Rs OK(String msg){
return new Rs(200,msg);
}
public static Rs error(){
return new Rs(500,"请求失败");
}
public static Rs error(String msg){
return new Rs(500,msg);
}
}
封装类的使用
@PostMapping("/login")
public Rs login1(@RequestBody User user) {
return Rs.OK("你好呀").put("token",user).put("ss","我是中XX");
}
返回结果
|