1、自己写一个实现类,里面包含3个属性和一些状态值,最主要的就是这个类要实现序列化
package com.auth.common;
import java.io.Serializable;
import java.util.List;
import com.elevator.liftRealTimeTask.entity.LiftRealTimeTask;
public class AjaxResult<T> implements Serializable {
private static final long serialVersionUID = -3291987235896997470L;
public static final Integer AJAX_STATUS_CODE_SUCCESS=0;
public static final Integer AJAX_STATUS_CODE_WARN=1;
public static final Integer AJAX_STATUS_CODE_ERROR=2;
private Integer statusCode;
private String message;
private T data;
public AjaxResult(){
super();
}
public AjaxResult(String message,Integer statusCode){
super();
this.statusCode=statusCode;
this.message=message;
}
public AjaxResult(String message,Integer statusCode,T data){
super();
this.statusCode=statusCode;
this.message=message;
this.data=data;
}
public static AjaxResult success(){
AjaxResult ajaxResult=new AjaxResult();
ajaxResult.setStatusCode(AjaxResult.AJAX_STATUS_CODE_SUCCESS);
ajaxResult.setMessage("操作成功");
return ajaxResult;
}
public AjaxResult success(T data){
AjaxResult ajaxResult=new AjaxResult();
ajaxResult.setStatusCode(AjaxResult.AJAX_STATUS_CODE_SUCCESS);
ajaxResult.setMessage("操作成功!");
ajaxResult.setData(data);
return ajaxResult;
}
//手机
/*public AjaxResult success(List list){
AjaxResult ajaxResult=new AjaxResult();
ajaxResult.setStatusCode(AjaxResult.AJAX_STATUS_CODE_SUCCESS);
ajaxResult.setMessage("操作成功");
ajaxResult.setData(list);
return ajaxResult;
}*/
public static AjaxResult error(){
AjaxResult ajaxResult=new AjaxResult();
ajaxResult.setStatusCode(AjaxResult.AJAX_STATUS_CODE_ERROR);
ajaxResult.setMessage("操作异常!");
return ajaxResult;
}
public static AjaxResult warn(){
AjaxResult ajaxResult=new AjaxResult();
ajaxResult.setStatusCode(AjaxResult.AJAX_STATUS_CODE_WARN);
return ajaxResult;
}
public Integer getStatusCode() {
return statusCode;
}
public void setStatusCode(Integer statusCode) {
this.statusCode = statusCode;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}