This commit is contained in:
Redkale
2017-12-28 10:53:34 +08:00
parent 2fd13d1481
commit 19d6a06bfa

View File

@@ -5,7 +5,6 @@
*/ */
package org.redkale.service; package org.redkale.service;
import java.io.Serializable;
import java.util.*; import java.util.*;
import org.redkale.convert.json.*; import org.redkale.convert.json.*;
@@ -30,7 +29,7 @@ public class RetResult<T> {
protected T result; protected T result;
protected Map<String, Serializable> attach; protected Map<String, String> attach;
public RetResult() { public RetResult() {
} }
@@ -110,7 +109,7 @@ public class RetResult<T> {
* *
* @return RetResult * @return RetResult
*/ */
public RetResult<T> attach(Map<String, Serializable> attach) { public RetResult<T> attach(Map<String, String> attach) {
this.attach = attach; this.attach = attach;
return this; return this;
} }
@@ -119,13 +118,14 @@ public class RetResult<T> {
* attach添加元素 * attach添加元素
* *
* @param key String * @param key String
* @param value Serializable * @param value String
* *
* @return RetResult * @return RetResult
*/ */
public RetResult<T> attach(String key, Serializable value) { public RetResult<T> attach(String key, Object value) {
if (this.attach == null) this.attach = new HashMap<>(); if (this.attach == null) this.attach = new HashMap<>();
this.attach.put(key, value); boolean canstr = value != null && (value instanceof CharSequence || value.getClass().isPrimitive());
this.attach.put(key, value == null ? null : (canstr ? String.valueOf(value) : JsonConvert.root().convertTo(value)));
return this; return this;
} }
@@ -183,26 +183,16 @@ public class RetResult<T> {
* *
* @return 结果附件 * @return 结果附件
*/ */
public Map<String, Serializable> getAttach() { public Map<String, String> getAttach() {
return attach; return attach;
} }
public Serializable findAttachValue(String key) {
return attach == null ? null : attach.get(key);
}
public String findAttachStringValue(String key) {
if (attach == null) return null;
Serializable val = attach.get(key);
return val == null ? null : val.toString();
}
/** /**
* 设置结果附件 * 设置结果附件
* *
* @param attach Map * @param attach Map
*/ */
public void setAttach(Map<String, Serializable> attach) { public void setAttach(Map<String, String> attach) {
this.attach = attach; this.attach = attach;
} }