packagecom.ts.common.model;importjava.io.Serializable;importcom.alibaba.fastjson.JSON;/*** 返回结果统一bean
*
* ResultBean
* 创建人:wangbeidou
* 时间:2018年4月12日-下午3:49:46
*@version2.0
**/
public class ResultBean implementsSerializable {private static final long serialVersionUID = 1L;//成功状态
public static final int SUCCESS = 1;//处理中状态
public static final int PROCESSING = 0;//失败状态
public static final int FAIL = -1;//描述
private String msg = "success";//状态默认成功
private int code =SUCCESS;//备注
privateString remark;//返回数据
privateT data;publicResultBean() {super();
}publicResultBean(T data) {super();this.data =data;
}/*** 使用异常创建结果*/
publicResultBean(Throwable e) {super();this.msg =e.toString();this.code =FAIL;
}/***
* 实例化结果默认成功状态
* 方法名:newInstance
* 创建人:wangbeidou
* 时间:2018年4月12日-下午3:51:26
*@returnResultBean
*@exception
*@since2.0*/
public static ResultBeannewInstance() {
ResultBean instance = new ResultBean();//默认返回信息
instance.code =SUCCESS;
instance.msg= "success";returninstance;
}/***
* 实例化结果默认成功状态和数据
* 方法名:newInstance
* 创建人:wangbeidou
* 时间:2018年5月10日-下午2:13:16
*@paramdata
*@returnResultBean
*@exception
*@since2.0*/
public static ResultBeannewInstance(T data) {
ResultBean instance = new ResultBean();//默认返回信息
instance.code =SUCCESS;
instance.msg= "success";
instance.data=data;returninstance;
}/***
* 实例化返回结果
* 方法名:newInstance
* 创建人:wangbeidou
* 时间:2018年4月12日-下午4:00:53
*@paramcode
*@parammsg
*@returnResultBean
*@exception
*@since2.0*/
public static ResultBean newInstance(intcode, String msg) {
ResultBean instance = new ResultBean();//默认返回信息
instance.code =code;
instance.msg=msg;returninstance;
}/***
* 实例化返回结果
* 方法名:newInstance
* 创建人:wangbeidou
* 时间:2018年4月12日-下午4:00:35
*@paramcode
*@parammsg
*@paramdata
*@returnResultBean
*@exception
*@since2.0*/
public static ResultBean newInstance(intcode, String msg, T data) {
ResultBean instance = new ResultBean();//默认返回信息
instance.code =code;
instance.msg=msg;
instance.data=data;returninstance;
}/***
* 设置返回数据
* 方法名:setData
* 创建人:wangbeidou
* 时间:2018年4月12日-下午3:52:01
*@paramdata
*@returnResultBean
*@exception
*@since2.0*/
public ResultBeansetData(T data){this.data =data;return this;
}/***
* 设置结果描述
* 方法名:setMsg
* 创建人:wangbeidou
* 时间:2018年4月12日-下午3:52:34
*@parammsg
*@returnResultBean
*@exception
*@since2.0*/
public ResultBeansetMsg(String msg){this.msg =msg;return this;
}/***
* 设置状态
* 方法名:setCode
* 创建人:wangbeidou
* 时间:2018年4月12日-下午4:17:56
*@paramcode
*@returnResultBean
*@exception
*@since2.0*/
public ResultBean setCode(intcode){this.code =code;return this;
}/***
* 设置备注)
* 方法名:setRemark
* 创建人:wangbeidou
* 时间:2018年4月12日-下午5:47:29
*@paramremark
*@returnResultBean
*@exception
*@since2.0*/
public ResultBeansetRemark(String remark){this.remark =remark;return this;
}/***
* 设置成功描述和返回数据
* 方法名:success
* 创建人:wangbeidou
* 时间:2018年4月12日-下午3:52:58
*@parammsg
*@paramdata
*@returnResultBean
*@exception
*@since2.0*/
public ResultBeansuccess(String msg, T data){this.code =SUCCESS;this.data =data;this.msg =msg;return this;
}/***
* 设置成功返回结果描述
* 方法名:success
* 创建人:wangbeidou
* 时间:2018年4月12日-下午3:53:31
*@parammsg
*@returnResultBean
*@exception
*@since2.0*/
public ResultBeansuccess(String msg){this.code =SUCCESS;this.msg =msg;return this;
}/***
* 设置处理中描述和返回数据
* 方法名:success
* 创建人:wangbeidou
* 时间:2018年4月12日-下午3:52:58
*@parammsg
*@paramdata
*@returnResultBean
*@exception
*@since2.0*/
public ResultBeanprocessing(String msg, T data){this.code =PROCESSING;this.data =data;this.msg =msg;return this;
}/***
* 设置处理中返回结果描述
* 方法名:success
* 创建人:wangbeidou
* 时间:2018年4月12日-下午3:53:31
*@parammsg
*@returnResultBean
*@exception
*@since2.0*/
public ResultBeanprocessing(String msg){this.code =PROCESSING;this.msg =msg;return this;
}/***
* 设置失败返回描述和返回数据
* 方法名:fail
* 创建人:wangbeidou
* 时间:2018年4月12日-下午3:54:04
*@parammsg
*@paramdata
*@returnResultBean
*@exception
*@since2.0*/
public ResultBeanfail(String msg, T data){this.code =FAIL;this.data =data;this.msg =msg;return this;
}/***
* 设置失败返回描述
* 方法名:fail
* 创建人:wangbeidou
* 时间:2018年4月12日-下午3:54:32
*@parammsg
*@returnResultBean
*@exception
*@since2.0*/
public ResultBeanfail(String msg){this.code =FAIL;this.msg =msg;return this;
}publicT getData() {returndata;
}publicString getMsg() {returnmsg;
}public intgetCode() {returncode;
}publicString getRemark() {returnremark;
}/***
* 生成json字符串
* 方法名:json
* 创建人:wangbeidou
* 时间:2018年4月12日-下午4:42:28
*@returnString
*@exception
*@since2.0*/
publicString json(){return JSON.toJSONString(this);
}
}