Graceful Response

Graceful Response是一个Spring Boot技术栈下的优雅响应处理器,提供统一返回值封装、全局异常处理、自定义异常错误码等功能,简化Web接口开发,提高代码质量。

Check out Graceful Response on CurateClick

• Copy the embed code to showcase this product on your website

• Share on X to spread the word about this amazing tool

  • 简介Graceful Response是一个Spring Boot技术栈下的优雅响应处理器,一站式地提供统一返回值封装、全局异常处理、自定义异常错误码、参数校验异常码等功能,使用Graceful Response进行web接口开发不仅可以节省大量的时间,还可以提高代码质量,使代码逻辑更清晰。- 仓库及文档项目仓库:https://github.com/feiniaojin/graceful-response文档地址:https://doc.feiniaojin.com/- 亮点零学习成本,maven引入之后,只需要在启动类加入@EnableGracefulResponse注解即可开启;功能全面,注解开启后即可拥有统一返回值封装、全局异常处理、异常与错误码映射等功能;兼容性强,支持SpringBoot 2.x和3.x版本,并兼容Swagger等组件;生产环境验证,该项目已在京东内部多个项目中使用。- 使用示例使用Graceful Response前的代码:javapublic class Controller { @GetMapping("/query") @ResponseBody public Response query(Parameter params) { Response res = new Response(); try { //1.校验params参数,非空校验、长度校验 if (illegal(params)) { res.setCode(1); res.setMsg("error"); return res; } //2.调用Service的一系列操作 Data data = service.query(params); //3.将操作结果设置到res对象中 res.setData(data); res.setCode(0); res.setMsg("ok"); return res; } catch (Exception e) { //3.异常处理:一堆丑陋的try...catch,如果有错误码的,还需要手工填充错误码 res.setCode(1); res.setMsg("error"); return res; } }}在启动类中使用注解开启Graceful Response:java@EnableGracefulResponse@SpringBootApplicationpublic class ExampleApplication { public static void main(String[] args) { SpringApplication.run(ExampleApplication.class, args); }}使用Graceful Response后的代码:javapublic class Controller { @GetMapping("/query") @ResponseBody public Data query(Parameter params) { //此处异常处理、返回结果封装全部交给Graceful Response,非常简洁清晰 Data data = service.query(params); return data; }}最终结果都会向前端返回如下格式的Reponse:json{ "code":"0", "msg":"msg", "data":{ }}- 其他功能第三方组件适配(Swagger、actuator等)、自定义自定义Response、例外请求放行、异常别名、常用配置项等功能,详细见文档中心- 后续更新计划目前Graceful Reponse的功能已经相当完善,基本已经覆盖SpringBoot Web接口开发的各种场景,未来会根据用户提的Issue进行功能迭代。

Latest Weekly Picks

make.ink favicon
Weekly Pick

Your AI tattoo generator for pro-grade concepts

Leo Wade
sellfy.com favicon
Weekly Pick

A code-free online store builder to turn views into revenue. Sell digital products, subscriptions, and merch, without fees or hassle.

Maris
www.videotoblog.ai favicon
Weekly Pick

Convert videos into awesome blog posts.

Video To Blog
www.sellerpic.ai favicon
Weekly Pick

SellerPic is the all-in-one AI design platform for e-commerce

SellerPic
fastimage.ai favicon
Weekly Pick

Fast Image AI instantly transforms your photos into stunning styles like Ghibli, Sketch, and Pixar. Effortlessly control image elements and create amazing effects with just one click.

Fast AI Team
linkedinpro.daisy.so favicon
Weekly Pick

AI-powered tool that transforms casual photos into professional LinkedIn headshots instantly. No photographer needed—just upload and download.

Gabriel
crevas.ai favicon
Weekly Pick

Crevas unifies Veo 3, Sora 2, Nano Banana and more into one intuitive canvas — so filmmakers can script, prompt, and generate cinematic stories without switching tools or losing consistency.

Spark Alpha
fotominiatur.com favicon
Weekly Pick

AI Foto Edit - Text to Image & Image Edit

foto miniatur