/**
* @Package com.XXXX.entity
* @Description: 接口返回结果封装
* @Author: admin
* @Date: 2018/5/1610:49
*/
public class Result<T> {
/**
* 返回状态码
*/
private String code;
/**
* 返回信息
*/
private String msg;
/**
* 返回数据
*/
private T data;
//如果返回数据直接成功
public Result(T data) {
this.code = "200";
this.data = data;
this.msg = "OK";
}
//失败调用
public Result(String msg) {
this.code = "-200";
this.msg = msg;
}
//构造方法
public Result(String code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
//成功直接返回数据和状态
public static<T> Result<T> ok(T data){
return new Result<T>(data);
}
//失败的时候调用
public static<T> Result<T> error(String msg){
return new Result<T>(msg);
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
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;
}
}
自己写的java返回结果集封装
猜你喜欢
转载自www.cnblogs.com/jpfss/p/9045073.html
今日推荐
周排行