-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
65 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 0 additions & 156 deletions
156
eva-core/eva-core-common/src/main/java/io/nerv/core/advice/JsonFilterAdvice.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
eva-web/eva-web-base/src/main/java/io/nerv/core/advice/CommonResponseAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.nerv.core.advice; | ||
|
||
import io.nerv.core.enums.BizCode; | ||
import io.nerv.core.enums.BizCodeEnum; | ||
import io.nerv.core.mvc.vo.Response; | ||
import org.springframework.core.MethodParameter; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.server.ServerHttpRequest; | ||
import org.springframework.http.server.ServerHttpResponse; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; | ||
|
||
/** | ||
* 统一处理返回值 | ||
* 注意 这里只对io.nerv包下的返回值自动响应处理 | ||
*/ | ||
@RestControllerAdvice(basePackages = "io.nerv") | ||
public class CommonResponseAdvice implements ResponseBodyAdvice { | ||
|
||
@Override | ||
public boolean supports(MethodParameter returnType, Class converterType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) { | ||
|
||
|
||
if (body instanceof Response){ | ||
return body; | ||
} | ||
Response res = new Response(); | ||
res.setSuccess(true); | ||
|
||
if (body instanceof BizCode){ | ||
res.setCode(((BizCode) body).getIndex()); | ||
res.setMessage(((BizCode) body).getName()); | ||
} else { | ||
res.setMessage(BizCodeEnum.OPERATE_SUCCESS.getIndex()); | ||
res.setData(body); | ||
} | ||
|
||
return res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters