GlobalResult
用于控制层返回一个信息
package com.itcast.utils;
public class GlobalResult {
private int code;
private String msg;
private Object data;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
private GlobalResult(int code, String msg, Object data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public static GlobalResult of(int code, String msg, Object data) {
return new GlobalResult(code, msg, data);
}
public static GlobalResult of(int code, String msg) {
return of(code, msg, null);
}
public static GlobalResult of(int code) {
return of(code, "");
}
public static GlobalResult ok() {
return ok("ok");
}
public static GlobalResult ok(String msg) {
return ok(msg, null);
}
public static GlobalResult ok(String msg, Object data) {
return of(200, msg, data);
}
public static GlobalResult error(String msg, Object data) {
return of(500, msg, data);
}
public static GlobalResult error(String msg) {
return error(msg, null);
}
public static GlobalResult error() {
return error("error");
}
}