-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加url请求例子
- Loading branch information
Showing
6 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
spring-boot-common/src/main/java/com/module/common/api/ResponseResult.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,125 @@ | ||
package com.module.common.api; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @Description | ||
* @Author lvxc | ||
* @Date 2021/4/26 10:54 | ||
**/ | ||
public class ResponseResult<T> implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* 状态码 | ||
**/ | ||
private int code; | ||
/** | ||
* 返回信息 | ||
**/ | ||
private String message; | ||
/** | ||
* 返回具体对象信息 | ||
**/ | ||
private T data; | ||
|
||
private String tid; | ||
|
||
public int getCode() { | ||
return code; | ||
} | ||
|
||
public ResponseResult<T> setCode(int code) { | ||
this.code = code; | ||
return this; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public ResponseResult<T> setMessage(String message) { | ||
this.message = message; | ||
return this; | ||
} | ||
|
||
public T getData() { | ||
return data; | ||
} | ||
|
||
public ResponseResult<T> setData(T data) { | ||
this.data = data; | ||
return this; | ||
} | ||
|
||
public String getTid() { | ||
return tid; | ||
} | ||
|
||
public ResponseResult<T> setTid(String tid) { | ||
this.tid = tid; | ||
return this; | ||
} | ||
|
||
public ResponseResult() { | ||
} | ||
|
||
public ResponseResult(int code) { | ||
this.code = code; | ||
} | ||
|
||
public ResponseResult(int code, String message) { | ||
this.message = message; | ||
this.code = code; | ||
} | ||
|
||
public ResponseResult(int code, String message, T data) { | ||
this.message = message; | ||
this.code = code; | ||
this.data = data; | ||
} | ||
|
||
public static <T> ResponseResult<T> success() { | ||
return new ResponseResult<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg()); | ||
} | ||
|
||
public static <T> ResponseResult<T> success(T data) { | ||
if (data == null) { | ||
List<T> a = new ArrayList<>(); | ||
data = (T) a; | ||
} | ||
return new ResponseResult<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(),data); | ||
} | ||
|
||
public static <T> ResponseResult<T> error(ResultEnum resultEnum) { | ||
ResponseResult<T> result = new ResponseResult<>(); | ||
result.setCode(resultEnum.getCode()); | ||
result.setMessage(resultEnum.getMsg()); | ||
return result; | ||
} | ||
|
||
public static <T> ResponseResult<T> error(Integer code, String msg) { | ||
return new ResponseResult<>(code, msg); | ||
} | ||
|
||
public static <T> ResponseResult<T> error() { | ||
return ResponseResult.error(ResultEnum.FAILED); | ||
} | ||
|
||
public static <T> ResponseResult<T> error(ResultEnum resultEnum, String msg) { | ||
return error(resultEnum.getCode(), msg); | ||
} | ||
|
||
public boolean isSuccess() { | ||
return Objects.equals(this.code, ResultEnum.SUCCESS.getCode()); | ||
} | ||
|
||
public boolean isError() { | ||
return !Objects.equals(this.code, ResultEnum.SUCCESS.getCode()); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
spring-boot-common/src/main/java/com/module/common/api/ResultEnum.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,26 @@ | ||
package com.module.common.api; | ||
|
||
public enum ResultEnum { | ||
SUCCESS(200, "成功"), | ||
FAILED(500, "操作失败"), | ||
VALIDATE_FAILED(404, "参数检验失败"), | ||
UNAUTHORIZED(401, "暂未登录或token已经过期"), | ||
FORBIDDEN(403, "没有相关权限"); | ||
|
||
private Integer code; | ||
|
||
private String message; | ||
|
||
ResultEnum(Integer code, String message) { | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
public Integer getCode() { | ||
return this.code; | ||
} | ||
|
||
public String getMsg() { | ||
return this.message; | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
spring-boot-web/src/main/java/com/module/web/controller/TestController.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,19 @@ | ||
package com.module.web.controller; | ||
|
||
import com.module.common.api.ResponseResult; | ||
import com.module.web.vo.TestVo; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
/** | ||
* @Description | ||
* @Author lvxc | ||
* @Date 2021/4/26 10:45 | ||
**/ | ||
@RestController | ||
@RequestMapping("/test") | ||
public class TestController { | ||
@PostMapping(value = "/insert") | ||
public ResponseResult<String> insert(@RequestBody TestVo vo) { | ||
return ResponseResult.success("你好"); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
spring-boot-web/src/main/java/com/module/web/vo/TestVo.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,11 @@ | ||
package com.module.web.vo; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* @Description | ||
* @Author lvxc | ||
* @Date 2021/4/26 10:50 | ||
**/ | ||
public class TestVo implements Serializable { | ||
} |
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,2 @@ | ||
server: | ||
port: 80 |