package com.ots.framework.web.domain;
|
import com.ots.common.utils.MessageUtils;
|
import com.ots.common.utils.StringUtils;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
import java.util.HashMap;
|
|
public class AjaxResult extends HashMap<String, Object> {
|
private static final long serialVersionUID = 1L;
|
public static final String CODE_TAG = "code";
|
public static final String MSG_TAG = "msg";
|
public static final String DATA_TAG = "data";
|
|
public enum Type {
|
|
SUCCESS(0),
|
|
WARN(301),
|
|
ERROR(500);
|
private final int value;
|
Type(int value) {
|
this.value = value;
|
}
|
public int value() {
|
return this.value;
|
}
|
}
|
|
private Type type;
|
|
private int code;
|
|
private String msg;
|
|
private Object data;
|
|
public AjaxResult() {
|
}
|
|
public AjaxResult(Type type, String msg) {
|
super.put(CODE_TAG, type.value);
|
super.put(MSG_TAG, msg);
|
}
|
|
public AjaxResult(Type type, String msg, Object data) {
|
super.put(CODE_TAG, type.value);
|
super.put(MSG_TAG, msg);
|
if (StringUtils.isNotNull(data)) {
|
super.put(DATA_TAG, data);
|
}
|
}
|
|
public static AjaxResult success() {
|
return AjaxResult.success(MessageUtils.message("basis.successfulOperation"));
|
}
|
|
public static AjaxResult success(Object data) {
|
return AjaxResult.success(MessageUtils.message("basis.successfulOperation"), data);
|
}
|
|
public static AjaxResult success(String msg) {
|
return AjaxResult.success(msg, null);
|
}
|
|
public static AjaxResult success(String msg, Object data) {
|
return new AjaxResult(Type.SUCCESS, msg, data);
|
}
|
|
public static AjaxResult warn(String msg) {
|
return AjaxResult.warn(msg, null);
|
}
|
|
public static AjaxResult warn(String msg, Object data) {
|
return new AjaxResult(Type.WARN, msg, data);
|
}
|
|
public static AjaxResult error() {
|
return AjaxResult.error("操作失败");
|
}
|
|
public static AjaxResult error(String msg) {
|
return AjaxResult.error(msg, null);
|
}
|
|
public static AjaxResult error(String msg, Object data) {
|
return new AjaxResult(Type.ERROR, msg, data);
|
}
|
public Type getType() {
|
return type;
|
}
|
public void setType(Type type) {
|
this.type = type;
|
}
|
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;
|
}
|
@Override
|
public String toString() {
|
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
.append("code", getCode())
|
.append("msg", getMsg())
|
.append("data", getData())
|
.toString();
|
}
|
}
|