|
@@ -1,6 +1,7 @@
|
|
|
package com.platform.util;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.platform.entity.Result;
|
|
|
import com.platform.entity.TokenEntity;
|
|
|
import com.platform.interceptor.AuthorizationInterceptor;
|
|
|
import com.platform.service.TokenService;
|
|
@@ -56,7 +57,7 @@ public class ApiBaseAction {
|
|
|
*/
|
|
|
@ExceptionHandler({BindException.class, MissingServletRequestParameterException.class, UnauthorizedException.class, TypeMismatchException.class})
|
|
|
@ResponseBody
|
|
|
- public Map<String, Object> bindException(Exception e) {
|
|
|
+ public Result bindException(Exception e) {
|
|
|
if (e instanceof BindException) {
|
|
|
return toResponsObject(1, "参数绑定异常", e.getMessage());
|
|
|
} else if (e instanceof UnauthorizedException) {
|
|
@@ -75,33 +76,20 @@ public class ApiBaseAction {
|
|
|
* @date 2016年9月2日
|
|
|
* @author zhuliyun
|
|
|
*/
|
|
|
- public Map<String, Object> toResponsObject(int requestCode, String msg, Object data) {
|
|
|
- Map<String, Object> obj = new HashMap<String, Object>();
|
|
|
- obj.put("errno", requestCode);
|
|
|
- obj.put("errmsg", msg);
|
|
|
- if (data != null)
|
|
|
- obj.put("data", data);
|
|
|
- return obj;
|
|
|
+ public Result toResponsObject(int requestCode, String msg, Object data) {
|
|
|
+ return Result.failure(requestCode,msg,data);
|
|
|
}
|
|
|
|
|
|
- public Map<String, Object> toResponsSuccess(Object data) {
|
|
|
- Map<String, Object> rp = toResponsObject(0, "执行成功", data);
|
|
|
- logger.info("response:{}",JSONObject.toJSONString(rp));
|
|
|
- return rp;
|
|
|
+ public Result toResponsSuccess(Object data) {
|
|
|
+ return Result.success(data);
|
|
|
}
|
|
|
|
|
|
- public Map<String, Object> toResponsMsgSuccess(String msg) {
|
|
|
- return toResponsObject(0, msg, "");
|
|
|
+ public Result toResponsMsgSuccess(String msg) {
|
|
|
+ return toResponsSuccess(msg);
|
|
|
}
|
|
|
|
|
|
- public Map<String, Object> toResponsSuccessForSelect(Object data) {
|
|
|
- Map<String, Object> result = new HashMap<>(2);
|
|
|
- result.put("list", data);
|
|
|
- return toResponsObject(0, "执行成功", result);
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, Object> toResponsFail(String msg) {
|
|
|
- return toResponsObject(1, msg, null);
|
|
|
+ public Result toResponsFail(String msg) {
|
|
|
+ return Result.failure(msg);
|
|
|
}
|
|
|
|
|
|
/**
|