1.对于API结果返回,定义BaseResult 类

拥有success,errorCode,errorMsg个3个基本参数,success使用Boolean类型,errorCode使用Integer类型,errorMsg使用String类型

对于success,false表示接口请求失败,true表示接口请求成功。

对于errorCode,当success=true时为0,其他请参阅ABBCCC格式错误码。

对于errorMsg,当success=true时为null,其他情况不为null。

如下图所示

java常见错误code java错误码_java常见错误code

2.错误码格式定义

统一格式:A-BB-CCC,6位长度整形int。

A:代表错误级别,1表示系统级错误,2表示服务级错误。

BB:代表错误项目或者模块号,从00开始。

CCC:具体错误编号,自增,从001开始。