DevOps研发效能
媒体矩阵
开源中国APP
授权协议 MIT
开发语言 Java
操作系统 跨平台
软件类型 开源软件
开源组织
地区 国产
投 递 者 冯文议
适用人群 未知
收录时间 2019-12-05

软件简介

API接口返回结果规范化解决方案

API 接口开发返回结果规范化解决方案

一、概述

Api Result,是 RESTful风格的API接口响应参数规范化的一套解决方案 。它是在实际应用环境下产生了,并不断更新和完善。 结合Spring Boot进行开发,让接口响应结果变得更加规范。

二、示例

{
    "code":"111111",
    "message":"Query Success",
    "success":true,
    "trace_id":"edf36a73796356d5bc9b6d81f4eb83d6",
    "body":{
        "categoryData":[
            {
                "id":"1265200246055809026",
                "categoryName":"公告"
            },
            {
                "id":"1257301514647777282",
                "categoryName":"Java"
            },
            {
                "id":"1257694082590060546",
                "categoryName":"开发"
            },
            {
                "id":"1257255039406452737",
                "categoryName":"前端"
            },
            {
                "id":"1257687302015299586",
                "categoryName":"计划"
            },
            {
                "id":"1258792800529727490",
                "categoryName":"网站更新日志"
            },
            {
                "id":"1257256132635013121",
                "categoryName":"日志"
            }
        ]
    }
}

三、实体类属性介绍

CommonResponse

序号 属性 类型 默认值 说明
1 code String   返回码
2 message String   返回码描述信息
3 success Boolean false 响应结果状态,true:表示成功;false:表示失败
4 traceId String   追溯码,json格式返回时,为 trace_id
5 header Map<String, String>   响应头
6 body 泛型 <T>   响应体

CommonPage

序号 属性 类型 默认值 说明
1 currentPage Long   当前页
2 pageSize Integer   每页显示条数
3 totalElements Long   总条数
4 totalPages Long   总页数
5 content 泛型 <T>   数据

四、返回方法介绍

返回成功

  • CommonResponse.ok()

  • CommonResponse.ok(data)

返回失败

  • CommonResponse.error()

  • CommonResponse.error(msg)

  • CommonResponse.error(code, msg)

  • CommonResponse.error(iError)

五、IError介绍

IError是返回码和描述信息的接口。

你可以在返回时,使用。

为了方便,提供了常见的错误,将其命名为 Default

你可以直接使用 IError.Default

值得注意的是:成功的返回码是6个1,字符型,111111 。

六、中央仓库

展开阅读全文

代码

的 Gitee 指数为
超过 的项目

评论

点击加入讨论🔥(5) 发布并加入讨论🔥
发表了资讯
2022/11/17 22:31

api-result 2.7.3 发布,API 接口返回结果规范化解决方案

api-result 2.7.3 已经发布,API 接口返回结果规范化解决方案。 New Features 新增 Boolean 结果类型响应类:BooleanResponse com.fengwenyi.api.result.StringUtils 改为只为本包使用 Builder -> IBuilder Result -> IResult Bug Fixes 修复 ResultTemplate.date 转json,可能出现无法被序列化的问题 Document 修复文档示例代码不正确的问题 详情查看:https://gitee.com/fengwenyi/api-result/releases/2.7.3...

0
1
发表了资讯
2022/04/03 05:25

api-result 2.5.3 发布,API 接口返回结果规范化解决方案

api-result 2.5.3 已经发布,API 接口返回结果规范化解决方案。 此版本更新内容包括: 【优化】返回的属性为空时不再自动隐藏,交由业务系统自行配置 【修复】ResponseTemplate 无参数构造方法 private > public,解决无法被继承的问题 【删除】删除依赖 jackson-annotations 详情查看:https://gitee.com/fengwenyi/api-result/releases/2.5.3...

0
3
发表了资讯
2021/10/24 16:49

api-result 2.5.1 发布,API 接口返回结果规范化解决方案

api-result 2.5.1 已经发布,API 接口返回结果规范化解决方案。 此版本更新内容包括: 这个是一个BUG修复版本 【新增】新增参数缺失和参数校验失败的返回码。 【修复】修复ResponseTemplate中fail相关的方法,code和message参数没有被赋值的问题。 【文档】README文档更新 【删除】删除images目录 【删除】删除version目录 详情查看:https://gitee.com/fengwenyi/api-result/releases/2.5.1...

0
4
发表了资讯
2021/10/22 10:52

api-result 2.5.0 发布,API 接口返回结果规范化解决方案

api-result 2.5.0 已经发布,API 接口返回结果规范化解决方案。 此版本更新内容包括: 【变更】ResultTemplate,code 类型改为 Integer 【变更】ResultTemplate,msg 改为 message 【变更】IReturnCode,getErrCode() 改为 getCode() 【变更】IReturnCode,getMsg() 改为 getMessage() 【变更】IReturnCode,getErrCode() 返回类型改为 Integer 【变更】IReturnCode,成功的返回码改为 0 【变更】IReturnCode,错误的返回码改为...

1
6
没有更多内容
加载失败,请刷新页面
点击加载更多
加载中
下一页
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
5 评论
33 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部