Spring Boot HTTP over JSON 的错误码异常处理

This commit is contained in:
JeffLi1993
2017-03-14 14:56:45 +08:00
committed by liqiangqiang
parent 0dad83ad48
commit ecfcb02e8d
3 changed files with 53 additions and 9 deletions

View File

@@ -0,0 +1,28 @@
package org.spring.springboot.result;
/**
* 应用系统级别的错误码
*
* Created by bysocket on 14/03/2017.
*/
public enum GlobalErrorInfoEnum implements ErrorInfoInterface{
SUCCESS("0", "success"),
NOT_FOUND("-1", "service not found");
private String code;
private String message;
GlobalErrorInfoEnum(String code, String message) {
this.code = code;
this.message = message;
}
public String getCode(){
return this.code;
}
public String getMessage(){
return this.message;
}
}

View File

@@ -5,7 +5,7 @@ package org.spring.springboot.result;
*
* Created by bysocket on 14/03/2017.
*/
public class ResultBody<T> {
public class ResultBody {
/**
* 响应代码
*/
@@ -19,13 +19,19 @@ public class ResultBody<T> {
/**
* 响应结果
*/
private T result;
private Object result;
public ResultBody(ErrorInfoInterface errorInfo) {
this.code = errorInfo.getCode();
this.message = errorInfo.getMessage();
}
public ResultBody(Object result) {
this.code = GlobalErrorInfoEnum.SUCCESS.getCode();
this.message = GlobalErrorInfoEnum.SUCCESS.getMessage();
this.result = result;
}
public String getCode() {
return code;
}
@@ -42,11 +48,11 @@ public class ResultBody<T> {
this.message = message;
}
public T getResult() {
public Object getResult() {
return result;
}
public void setResult(T result) {
public void setResult(Object result) {
this.result = result;
}
}