mirror of
https://github.com/JeffLi1993/springboot-learning-example.git
synced 2026-03-16 16:23:46 +08:00
Spring Boot HTTP over JSON 的错误码异常处理
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user