Here, a data returned to the page is encapsulated in the form of k, v key-value pairs
Separately encapsulate errorand okwait for two methods, and each method has a single construction method that can be used, and returns itself, which is convenient for assembling data later
putThe method is to put the data to be returned to the page
publicclassRextendsHashMap<String, Object>{
privatestaticfinallong serialVersionUID =1L;publicR(){
put("code",0);put("msg","success");}publicstatic R error(){
returnerror(HttpStatus.SC_INTERNAL_SERVER_ERROR,"未知异常,请联系管理员");}publicstatic R error(String msg){
returnerror(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);}publicstatic R error(int code, String msg){
R r =newR();
r.put("code", code);
r.put("msg", msg);return r;}publicstatic R ok(String msg){
R r =newR();
r.put("msg", msg);return r;}publicstatic R ok(Map<String, Object> map){
R r =newR();
r.putAll(map);return r;}publicstatic R ok(){
returnnewR();}public R put(String key, Object value){
super.put(key, value);returnthis;}}