Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

spring boot统一业务异常处理,统一返回格式包装

Notifications You must be signed in to change notification settings

xuanbo/rest-spring-boot-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

rest-spring-boot-starter

统一业务异常处理,统一返回格式包装

依赖

<dependency>
    <groupId>tk.fishfish</groupId>
    <artifactId>rest-spring-boot-starter</artifactId>
    <version>1.1.0.RELEASE</version>
</dependency>

统一业务异常处理

@RestController
public class DemoController {

    @GetMapping("/list")
    public List<String> list() {
        throw new BizException(10001, "xxx错误");
    }

}

业务异常统一处理:

{
    "code": 10001,
    "msg": "xxx错误",
    "data": null
}

统一返回格式包装

@RestController
public class DemoController {

    @GetMapping("/list")
    public List<String> list() {
        return Arrays.asList("1", "2");
    }

}

默认(增加 @ApiResultIgnore 注解可忽略)对返回值进行统一包装,忽略org.springframework.http.ResponseEntity值类型。

{
    "code": 0,
    "msg": null,
    "data": [
        "1",
        "2"
    ]
}

1.1.0.RELEASE

  • 增加 @ApiResultIgnore 注解,显式声明不包装 API 返回结果

1.0.0.RELEASE

  • 统一业务异常处理
  • 统一 API 返回格式包装

About

spring boot统一业务异常处理,统一返回格式包装

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages