自定义返回值类型
java自定义返回值类,如下所示:
/** *自定义返回值类型 */ public class Msg { //响应状态码 private int code; //响应信息 private String msg; //用户要返回给浏览器的数据 private Map<String,Object> extend = new HashMap<String,Object>(); //静态方法方便通过类名调用,返回值为Msg当前对象,便于链式操作 public static Msg success(){ Msg msg = new Msg(); msg.setCode(200); msg.setMsg("处理成功"); return msg; } public static Msg fail(){ Msg msg = new Msg(); msg.setCode(500); msg.setMsg("处理失败"); return msg; } public Msg add(String key,Object value){ this.getExtend().put(key,value); return this; } // 属性对应的getter/setter方法 public int getCode() { return code; } public String getMsg() { return msg; } public Map<String, Object> getExtend() { return extend; } public void setCode(int code) { this.code = code; } public void setMsg(String msg) { this.msg = msg; } public void setExtend(Map<String, Object> extend) { this.extend = extend; } }