Pre Merge pull request !310 from 郑/master
This commit is contained in:
commit
9b17bc5e75
1
pom.xml
1
pom.xml
|
|
@ -23,6 +23,7 @@
|
||||||
<bitwalker.version>1.21</bitwalker.version>
|
<bitwalker.version>1.21</bitwalker.version>
|
||||||
<kaptcha.version>2.3.2</kaptcha.version>
|
<kaptcha.version>2.3.2</kaptcha.version>
|
||||||
<swagger.version>3.0.0</swagger.version>
|
<swagger.version>3.0.0</swagger.version>
|
||||||
|
<swagger-annotations.version>1.6.2</swagger-annotations.version>
|
||||||
<mybatis-spring-boot.version>2.1.4</mybatis-spring-boot.version>
|
<mybatis-spring-boot.version>2.1.4</mybatis-spring-boot.version>
|
||||||
<pagehelper.boot.version>1.3.1</pagehelper.boot.version>
|
<pagehelper.boot.version>1.3.1</pagehelper.boot.version>
|
||||||
<fastjson.version>1.2.78</fastjson.version>
|
<fastjson.version>1.2.78</fastjson.version>
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,11 @@
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.swagger</groupId>
|
||||||
|
<artifactId>swagger-annotations</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,46 +1,95 @@
|
||||||
package com.ruoyi.common.core.domain;
|
package com.ruoyi.common.core.domain;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作消息提醒
|
* 操作消息提醒
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class AjaxResult extends HashMap<String, Object>
|
public class AjaxResult<T> extends HashMap<String, Object> {
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/** 状态码 */
|
/**
|
||||||
public static final String CODE_TAG = "code";
|
* 状态码
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "code : 返回代码,0表示OK,其它的都有对应问题")
|
||||||
|
public int code;
|
||||||
|
|
||||||
/** 返回内容 */
|
/**
|
||||||
public static final String MSG_TAG = "msg";
|
* 返回内容
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "msg : 如果code!=0,错误信息")
|
||||||
|
public String msg;
|
||||||
|
|
||||||
/** 数据对象 */
|
@ApiModelProperty(value = "如果code!=0,message的补充信息")
|
||||||
public static final String DATA_TAG = "data";
|
private Object exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据对象
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "code为0时返回结果集")
|
||||||
|
public T data = (T) new Object();
|
||||||
|
|
||||||
|
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 getException() {
|
||||||
|
return exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setException(Object exception) {
|
||||||
|
this.exception = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(T data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态类型
|
* 状态类型
|
||||||
*/
|
*/
|
||||||
public enum Type
|
public enum Type {
|
||||||
{
|
/**
|
||||||
/** 成功 */
|
* 成功
|
||||||
|
*/
|
||||||
SUCCESS(0),
|
SUCCESS(0),
|
||||||
/** 警告 */
|
/**
|
||||||
|
* 警告
|
||||||
|
*/
|
||||||
WARN(301),
|
WARN(301),
|
||||||
/** 错误 */
|
/**
|
||||||
|
* 错误
|
||||||
|
*/
|
||||||
ERROR(500);
|
ERROR(500);
|
||||||
private final int value;
|
private final int value;
|
||||||
|
|
||||||
Type(int value)
|
Type(int value) {
|
||||||
{
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int value()
|
public int value() {
|
||||||
{
|
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,8 +97,7 @@ public class AjaxResult extends HashMap<String, Object>
|
||||||
/**
|
/**
|
||||||
* 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。
|
* 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。
|
||||||
*/
|
*/
|
||||||
public AjaxResult()
|
public AjaxResult() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -58,10 +106,9 @@ public class AjaxResult extends HashMap<String, Object>
|
||||||
* @param type 状态类型
|
* @param type 状态类型
|
||||||
* @param msg 返回内容
|
* @param msg 返回内容
|
||||||
*/
|
*/
|
||||||
public AjaxResult(Type type, String msg)
|
public AjaxResult(Type type, String msg) {
|
||||||
{
|
super.put(String.valueOf(code), type.value);
|
||||||
super.put(CODE_TAG, type.value);
|
super.put(msg, msg);
|
||||||
super.put(MSG_TAG, msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -71,16 +118,26 @@ public class AjaxResult extends HashMap<String, Object>
|
||||||
* @param msg 返回内容
|
* @param msg 返回内容
|
||||||
* @param data 数据对象
|
* @param data 数据对象
|
||||||
*/
|
*/
|
||||||
public AjaxResult(Type type, String msg, Object data)
|
public AjaxResult(Type type, String msg, Object data) {
|
||||||
{
|
super.put(String.valueOf(code), type.value);
|
||||||
super.put(CODE_TAG, type.value);
|
super.put(msg, msg);
|
||||||
super.put(MSG_TAG, msg);
|
if (StringUtils.isNotNull(data)) {
|
||||||
if (StringUtils.isNotNull(data))
|
super.put((String) data, data);
|
||||||
{
|
|
||||||
super.put(DATA_TAG, data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AjaxResult(String errorMsg) {
|
||||||
|
this.msg = errorMsg;
|
||||||
|
this.code = 500;
|
||||||
|
this.data = (T) new Object();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AjaxResult(String errorMsg, int code) {
|
||||||
|
this.msg = errorMsg;
|
||||||
|
this.code = code;
|
||||||
|
this.data = (T) new Object();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 方便链式调用
|
* 方便链式调用
|
||||||
*
|
*
|
||||||
|
|
@ -89,8 +146,7 @@ public class AjaxResult extends HashMap<String, Object>
|
||||||
* @return 数据对象
|
* @return 数据对象
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult put(String key, Object value)
|
public AjaxResult put(String key, Object value) {
|
||||||
{
|
|
||||||
super.put(key, value);
|
super.put(key, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -100,9 +156,11 @@ public class AjaxResult extends HashMap<String, Object>
|
||||||
*
|
*
|
||||||
* @return 成功消息
|
* @return 成功消息
|
||||||
*/
|
*/
|
||||||
public static AjaxResult success()
|
public static AjaxResult success() {
|
||||||
{
|
AjaxResult result = new AjaxResult<>();
|
||||||
return AjaxResult.success("操作成功");
|
result.setCode(Type.SUCCESS.value);
|
||||||
|
result.setMsg("操作成功");
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -110,9 +168,10 @@ public class AjaxResult extends HashMap<String, Object>
|
||||||
*
|
*
|
||||||
* @return 成功消息
|
* @return 成功消息
|
||||||
*/
|
*/
|
||||||
public static AjaxResult success(Object data)
|
public static AjaxResult success(Object data) {
|
||||||
{
|
AjaxResult result = AjaxResult.success();
|
||||||
return AjaxResult.success("操作成功", data);
|
result.setData(data);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -121,9 +180,10 @@ public class AjaxResult extends HashMap<String, Object>
|
||||||
* @param msg 返回内容
|
* @param msg 返回内容
|
||||||
* @return 成功消息
|
* @return 成功消息
|
||||||
*/
|
*/
|
||||||
public static AjaxResult success(String msg)
|
public static AjaxResult success(String msg) {
|
||||||
{
|
AjaxResult result = AjaxResult.success();
|
||||||
return AjaxResult.success(msg, null);
|
result.setMsg(msg);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -133,9 +193,11 @@ public class AjaxResult extends HashMap<String, Object>
|
||||||
* @param data 数据对象
|
* @param data 数据对象
|
||||||
* @return 成功消息
|
* @return 成功消息
|
||||||
*/
|
*/
|
||||||
public static AjaxResult success(String msg, Object data)
|
public static AjaxResult success(String msg, Object data) {
|
||||||
{
|
AjaxResult result = AjaxResult.success();
|
||||||
return new AjaxResult(Type.SUCCESS, msg, data);
|
result.setData(data);
|
||||||
|
result.setMsg(msg);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -144,9 +206,11 @@ public class AjaxResult extends HashMap<String, Object>
|
||||||
* @param msg 返回内容
|
* @param msg 返回内容
|
||||||
* @return 警告消息
|
* @return 警告消息
|
||||||
*/
|
*/
|
||||||
public static AjaxResult warn(String msg)
|
public static AjaxResult warn(String msg) {
|
||||||
{
|
AjaxResult result = new AjaxResult();
|
||||||
return AjaxResult.warn(msg, null);
|
result.setCode(Type.WARN.value);
|
||||||
|
result.setMsg(msg);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -156,9 +220,10 @@ public class AjaxResult extends HashMap<String, Object>
|
||||||
* @param data 数据对象
|
* @param data 数据对象
|
||||||
* @return 警告消息
|
* @return 警告消息
|
||||||
*/
|
*/
|
||||||
public static AjaxResult warn(String msg, Object data)
|
public static AjaxResult warn(String msg, Object data) {
|
||||||
{
|
AjaxResult result = AjaxResult.warn(msg);
|
||||||
return new AjaxResult(Type.WARN, msg, data);
|
result.setData(data);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -166,9 +231,11 @@ public class AjaxResult extends HashMap<String, Object>
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static AjaxResult error()
|
public static AjaxResult error() {
|
||||||
{
|
AjaxResult result = new AjaxResult<>();
|
||||||
return AjaxResult.error("操作失败");
|
result.setCode(Type.ERROR.value);
|
||||||
|
result.setMsg("操作失败");
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -177,9 +244,10 @@ public class AjaxResult extends HashMap<String, Object>
|
||||||
* @param msg 返回内容
|
* @param msg 返回内容
|
||||||
* @return 警告消息
|
* @return 警告消息
|
||||||
*/
|
*/
|
||||||
public static AjaxResult error(String msg)
|
public static AjaxResult error(String msg) {
|
||||||
{
|
AjaxResult result = AjaxResult.error();
|
||||||
return AjaxResult.error(msg, null);
|
result.setMsg(msg);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -189,8 +257,10 @@ public class AjaxResult extends HashMap<String, Object>
|
||||||
* @param data 数据对象
|
* @param data 数据对象
|
||||||
* @return 警告消息
|
* @return 警告消息
|
||||||
*/
|
*/
|
||||||
public static AjaxResult error(String msg, Object data)
|
public static AjaxResult error(String msg, Object data) {
|
||||||
{
|
AjaxResult result = AjaxResult.error();
|
||||||
return new AjaxResult(Type.ERROR, msg, data);
|
result.setMsg(msg);
|
||||||
|
result.setData(data);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue