mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-12-26 14:15:41 +08:00
更换单点注销接口响应格式
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package cn.dev33.satoken.exception;
|
||||
|
||||
/**
|
||||
* 一个异常:代表 JSON 转换失败
|
||||
*
|
||||
* @author kong
|
||||
*/
|
||||
public class SaJsonConvertException extends SaTokenException {
|
||||
|
||||
/**
|
||||
* 序列化版本号
|
||||
*/
|
||||
private static final long serialVersionUID = 6806129545290134144L;
|
||||
|
||||
/**
|
||||
* 一个异常:代表 JSON 转换失败
|
||||
*/
|
||||
public SaJsonConvertException(Throwable e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,11 +21,33 @@ public class SaResult extends LinkedHashMap<String, Object> implements Serializa
|
||||
public static final int CODE_SUCCESS = 200;
|
||||
public static final int CODE_ERROR = 500;
|
||||
|
||||
/**
|
||||
* 构建
|
||||
*/
|
||||
public SaResult() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建
|
||||
* @param code 状态码
|
||||
* @param msg 信息
|
||||
* @param data 数据
|
||||
*/
|
||||
public SaResult(int code, String msg, Object data) {
|
||||
this.setCode(code);
|
||||
this.setMsg(msg);
|
||||
this.setData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 Map 快速构建
|
||||
* @param map /
|
||||
*/
|
||||
public SaResult(Map<String, Object> map) {
|
||||
for (String key: map.keySet()) {
|
||||
this.set(key, map.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取code
|
||||
@@ -138,9 +160,16 @@ public class SaResult extends LinkedHashMap<String, Object> implements Serializa
|
||||
public String toString() {
|
||||
return "{"
|
||||
+ "\"code\": " + this.getCode()
|
||||
+ ", \"msg\": \"" + this.getMsg() + "\""
|
||||
+ ", \"data\": \"" + this.getData() + "\""
|
||||
+ ", \"msg\": " + transValue(this.getMsg())
|
||||
+ ", \"data\": " + transValue(this.getData())
|
||||
+ "}";
|
||||
}
|
||||
|
||||
private String transValue(Object value) {
|
||||
if(value instanceof String) {
|
||||
return "\"" + value + "\"";
|
||||
}
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user