首页 > 编程知识 正文

微服务架构部署,httptemplate

时间:2023-05-04 01:19:53 阅读:16251 作者:4557

ErrCode ** *错误代码枚举*/public enum ErrCode { /** *系统错误*/system_error(1000, '定义系统错误')、/** *参数错误*/parameter _ error/* *参数错误*/not_null_error(1002,'参数可以为空“文件类型错误”、/** *数据permit_fail(400401、“没有相关权限”)、u nlogin (401、“未登录”)和/** *操作失败通常用于修改和删除,* /故障) 1004,“操作失败”integer代码; 字符串msg; 错误代码(integer code,String msg ) { this.code=code; this.msg=msg; }公共静态final map integer,String ERR_CODE=new HashMap (; 静态{ for (errcode errcode : errcode.values () err _ code.put (errcode.getcode ),errCode.getMsg ) ) } }公共integer getcode () { return code; } publicstaticstringgetmsg (integer代码) stringmsg=err_code.get )代码; if (! stringutils.isempty(msg ) ) { return msg; }返回空值; }1、定义执行

/* * @ authorlyl */@ sl F4 jpublicclassunloginexceptionextendsruntimeexception { @ getterprivateintegercode=401; @ getter私有字符串消息; @ getter private对象数据; publicunloginexception((this ) errcode.unlogin.getcode )、ErrCode.UNLOGIN.getMsg )、null ); } publicunloginexception (objectdata ) this ) errcode.unlogin.getcode )、ErrCode.UNLOGIN.getMsg )、data; } publicunloginexception (intcode,String message,Object data ) if ) code==0) thrownewruntimeexception ) '0are not not allocata } this.code=code; this.message=message; this.data=data; }全局异常处理系统/***@authorlyl*/@ slf4j @ restcontrolleradvicepublicclassglobalexceptionhandler { @ responsestatus (http status这是已修改的状态吗@ exception handler unloginexceptionhandler (unloginexceptione (log.error ) )。 RESRES=newRES(e.getcode (,e.getMessage ),e.getData ) ); 返回RES; }抛出异常的throw new UnLoginException ()或更高版本的四个步骤可以在抛出异常时修改http状态代码。 主要用于前端分离时,前端根据状态进行页面跳转。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。