https://github.com/xuanbo/rest-spring-boot-starter
spring boot统一业务异常处理,统一返回格式包装
https://github.com/xuanbo/rest-spring-boot-starter
global-exception-handling rest-api spring-boot
Last synced: 3 months ago
JSON representation
spring boot统一业务异常处理,统一返回格式包装
- Host: GitHub
- URL: https://github.com/xuanbo/rest-spring-boot-starter
- Owner: xuanbo
- Archived: true
- Created: 2019-11-05T12:41:44.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-22T03:33:55.000Z (about 5 years ago)
- Last Synced: 2025-07-08T23:17:54.603Z (9 months ago)
- Topics: global-exception-handling, rest-api, spring-boot
- Language: Java
- Size: 6.84 KB
- Stars: 2
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# rest-spring-boot-starter
> 统一业务异常处理,统一返回格式包装
## 依赖
```xml
tk.fishfish
rest-spring-boot-starter
1.1.0.RELEASE
```
## 统一业务异常处理
```java
@RestController
public class DemoController {
@GetMapping("/list")
public List list() {
throw new BizException(10001, "xxx错误");
}
}
```
业务异常统一处理:
```json
{
"code": 10001,
"msg": "xxx错误",
"data": null
}
```
## 统一返回格式包装
```java
@RestController
public class DemoController {
@GetMapping("/list")
public List list() {
return Arrays.asList("1", "2");
}
}
```
默认(增加 @ApiResultIgnore 注解可忽略)对返回值进行统一包装,忽略`org.springframework.http.ResponseEntity`值类型。
```json
{
"code": 0,
"msg": null,
"data": [
"1",
"2"
]
}
```
### 1.1.0.RELEASE
- 增加 @ApiResultIgnore 注解,显式声明不包装 API 返回结果
### 1.0.0.RELEASE
- 统一业务异常处理
- 统一 API 返回格式包装