# 左神-算法与数据结构全阶班

@GetMapping("/hello")
public String getStr(){
}

@GetMapping("/aniaml")
public Aniaml getAniaml(){
Aniaml aniaml = new Aniaml(1,"pig");
return aniaml;
}

{
"id": 1,
"name": "pig"
}

@GetMapping("/error")
public int error(){

``````int i = 9/0;
return i;``````

}

{
"timestamp": "2021-07-08T08:05:15.423+00:00",
"status": 500,
"error": "Internal Server Error",
"path": "/wrong"
}

status 状态值：由后端统一定义各种返回结果的状态码
message 描绘：本次接口调用的结果描绘
data 数据：本次返回的数据。
{
"status":"100",
"message":"操作胜利",
}

timestamp: 接口调用时间

@Data
public class ResultData {
/* 结果状态 ,详细状态码参见ResultData.java/
private int status;
private String message;
private T data;
private long timestamp ;
public ResultData (){

``this.timestamp = System.currentTimeMillis();``

}
public static ResultData success(T data) {

``````ResultData resultData = new ResultData<>();
resultData.setStatus(ReturnCode.RC100.getCode());
resultData.setMessage(ReturnCode.RC100.getMessage());
resultData.setData(data);
return resultData;``````

}
public static ResultData fail(int code, String message) {

``````ResultData resultData = new ResultData<>();
resultData.setStatus(code);
resultData.setMessage(message);
return resultData;``````

}
}

public enum ReturnCode {

``````/**操作胜利**/
RC100(100,"操作胜利"),
/**操作失败**/
RC999(999,"操作失败"),
/**效劳限流**/
RC200(200,"效劳开启限流维护,请稍后再试!"),
/**效劳降级**/
RC201(201,"效劳开启降级维护,请稍后再试!"),
/**热点参数限流**/
RC202(202,"热点参数限流,请稍后再试!"),
/**系统规则不满足**/
RC203(203,"系统规则不满足请求,请稍后再试!"),
/**受权规则不经过**/
RC204(204,"受权规则不经过,请稍后再试!"),
/**access_denied**/
RC403(403,"无访问权限,请联络管理员授予权限"),
/**access_denied**/
RC401(401,"匿名用户访问无权限资源时的异常"),
/**效劳异常**/
RC500(500,"系统异常，请稍后重试"),
INVALID_TOKEN(2001,"访问令牌不合法"),
ACCESS_DENIED(2003,"没有权限访问该资源"),
CLIENT_AUTHENTICATION_FAILED(1001,"客户端认证失败"),
UNSUPPORTED_GRANT_TYPE(1003, "不支持的认证形式");
/**自定义状态码**/
private final int code;
/**自定义描绘**/
private final String message;
ReturnCode(int code, String message){
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}``````

}

@GetMapping("/hello")
public ResultData getStr(){

``return ResultData.success("hello,javadaily");``

}

{
"status": 100,