diff --git a/spring-boot-activiti/src/main/java/com/lance/activiti/common/result/ResponseBodyInfo.java b/spring-boot-activiti/src/main/java/com/lance/activiti/common/result/ResponseBodyInfo.java new file mode 100644 index 0000000..b548c1e --- /dev/null +++ b/spring-boot-activiti/src/main/java/com/lance/activiti/common/result/ResponseBodyInfo.java @@ -0,0 +1,54 @@ +package com.lance.activiti.common.result; + +public class ResponseBodyInfo { + // 错误代码 + private int errorCode; + // 错误提示 + private String errorText; + + // 返回对象 + private T data; + + protected ResponseBodyInfo() { + } + + protected ResponseBodyInfo(int errorCode, String errorText, T data) { + this.errorCode = errorCode; + this.errorText = errorText; + this.data = data; + } + + public int getErrorCode() { + return errorCode; + } + + public void setErrorCode(int errorCode) { + this.errorCode = errorCode; + } + + public String getErrorText() { + return errorText; + } + + public void setErrorText(String errorText) { + this.errorText = errorText; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("ResponseBodyInfo{"); + sb.append("errorCode=").append(errorCode); + sb.append(", errorText='").append(errorText).append('\''); + sb.append(", data=").append(data); + sb.append('}'); + return sb.toString(); + } +} \ No newline at end of file diff --git a/spring-boot-activiti/src/main/java/com/lance/activiti/common/result/ResultInfo.java b/spring-boot-activiti/src/main/java/com/lance/activiti/common/result/ResultInfo.java new file mode 100644 index 0000000..79225df --- /dev/null +++ b/spring-boot-activiti/src/main/java/com/lance/activiti/common/result/ResultInfo.java @@ -0,0 +1,57 @@ +package com.lance.activiti.common.result; + +import com.lance.activiti.utils.FastJsonUtils; + +public class ResultInfo { + /** + * 执行成功 + * @return + * @author lance + * 2015年12月30日 下午11:40:15 + */ + public synchronized static String success() { + return success(null, null); + } + + /** + * 执行成功 + * @return + * @author lance + * 2015年12月30日 下午11:40:15 + */ + public synchronized static String success(Object obj) { + return success(obj, null); + } + /** + * 转化执行成功, 并把成功的结果以JSON对象传给前端 + * @param obj 转化的对象 + * @param filterPropNames 需要过滤的字段 + * @author lance + * 2015年12月30日 下午11:40:34 + */ + public synchronized static String success(Object obj, String[] filterPropNames) { + return success(obj, true, filterPropNames); + } + + public synchronized static String success(Object obj, boolean isRefDetect, String[] filterPropNames) { + ResponseBodyInfobody = new ResponseBodyInfo<>(0, "", obj); + return FastJsonUtils.toJson(body, isRefDetect, filterPropNames); + } + + + /** + * 返回错误对象 + * @param code 错误代码 + * @param message 错误信息 + * @author lance + * 2015年12月30日 下午11:36:32 + */ + public synchronized static String error(int code, String message) { + return error(code, message, null); + } + + public synchronized static String error(int code, String message, Object obj) { + ResponseBodyInfobody = new ResponseBodyInfo<>(code, message, obj); + return FastJsonUtils.entityToJsonSimple(body); + } +} \ No newline at end of file