Java中响应结果工具类,可自定义响应码,内容,响应消息
/**
* 响应结构
* @author yliu
*/
public class resultutil<t> {
// 响应业务状态
private integer status;
// 响应消息
private string msg;
// 响应中的数据
private t data;
public integer getstatus() {
return status;
}
public void setstatus(integer status) {
this.status = status;
}
public string getmsg() {
return msg;
}
public void setmsg(string msg) {
this.msg = msg;
}
public t getdata() {
return data;
}
public void setdata(t data) {
this.data = data;
}
public resultutil(integer status, string msg, t data) {
this.status = status;
this.msg = msg;
this.data = data;
}
public resultutil(t data) {
this.status = 2000;
this.msg = "success";
this.data = data;
}
public resultutil() {
this.status = 2001;
this.msg = "error";
this.data = null;
}
public static <t> resultutil<t> success(t data) {
return new resultutil<t>(data);
}
public static <t> resultutil<t> error(t data) {
return new resultutil<t>(2001, "error", data);
}
@override
public string tostring() {
return "resultutil [status=" + status + ", msg=" + msg + ", data=" + data + "]";
}
}
上一篇: 转载Linux下开启MySQL日志