Skip to content

Commit 646caf9

Browse files
author
pedro
committed
feat:添加response帮助函数
1 parent 041441f commit 646caf9

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/main/java/io/github/talelin/merak/common/utils/ResponseUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public static HttpServletResponse getResponse() {
3030
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
3131
}
3232

33+
public static void setCurrentResponseHttpStatus(int httpStatus) {
34+
getResponse().setStatus(httpStatus);
35+
}
36+
3337
public static UnifyResponseVO generateUnifyResponse(HttpException e) {
3438
return UnifyResponseVO.builder()
3539
.message(e.getMessage())
@@ -56,6 +60,7 @@ public static <T> UnifyResponseVO<T> generateUnifyResponse(int code) {
5660

5761
public static <T> UnifyResponseVO<T> generateCreatedResponse(T data) {
5862
Created created = new Created();
63+
setCurrentResponseHttpStatus(created.getHttpCode());
5964
return (UnifyResponseVO<T>) UnifyResponseVO.builder()
6065
.message(data)
6166
.code(created.getCode())
@@ -64,6 +69,7 @@ public static <T> UnifyResponseVO<T> generateCreatedResponse(T data) {
6469
}
6570

6671
public static <T> UnifyResponseVO<T> generateUnifyResponse(Code code, int httpCode) {
72+
setCurrentResponseHttpStatus(httpCode);
6773
return (UnifyResponseVO<T>) UnifyResponseVO.builder()
6874
.code(code.getCode())
6975
.message(code.getDescription())

0 commit comments

Comments
 (0)