当前位置: 首页 > news >正文

西宁做网站需要多少钱两个路由器做双网站

西宁做网站需要多少钱,两个路由器做双网站,线上营销怎么做,gae wordpress文章目录 1 定义错误码类2 定义业务异常类3 全局异常处理器4 使用5 前端请求效果总结 1 定义错误码类 ​ 可以定义各种错误码枚举#xff0c;比如业务#xff0c;系统相关的报错信息 /*** 错误代码* 错误码** author leovany* date 2023/09/23*/ public enum ErrorCode {SU… 文章目录 1 定义错误码类2 定义业务异常类3 全局异常处理器4 使用5 前端请求效果总结 1 定义错误码类 ​ 可以定义各种错误码枚举比如业务系统相关的报错信息 /*** 错误代码* 错误码** author leovany* date 2023/09/23*/ public enum ErrorCode {SUCCESS(0, success, ),ERROR_PARAMS(40000, 请求参数错误, ),ERROR_NULL(40001, 请求数据为空, ),ERROR_LOGIN(40100, 未登录, ),ERROR_NO_AUTH(41001, 无权限, ),ERROR_SYSTEM(50000, 系统内部异常, );/*** 错误码ID*/private final int code;/*** 错误码信息*/private final String message;/*** 错误码描述详情*/private final String description;ErrorCode(int code, String message, String description) {this.code code;this.message message;this.description description;}public int getCode() {return code;}public String getMessage() {return message;}public String getDescription() {return description;} } 2 定义业务异常类 相对于 java 的异常类支持更多字段 扩展了 code和description两个字段 自定义构造函数更灵活 / 快捷的设置字段 import com.leovany.usercenter.common.ErrorCode;/*** 业务异常* 自定义业务异常类** author leovany* date 2023/09/23*/ public class BusinessException extends RuntimeException {/*** 错误码*/private final int code;/*** 描述*/private final String description;/*** 业务异常** param message 信息* param code 错误码* param description 描述*/public BusinessException(String message, int code, String description) {super(message);this.code code;this.description description;}/*** 业务异常** param errorCode 错误代码*/public BusinessException(ErrorCode errorCode) {super(errorCode.getMessage());this.code errorCode.getCode();this.description errorCode.getDescription();}/*** 业务异常** param errorCode 错误代码* param description 描述*/public BusinessException(ErrorCode errorCode, String description) {super(errorCode.getMessage());this.code errorCode.getCode();this.description description;}public int getCode() {return code;}public String getDescription() {return description;} } 3 全局异常处理器 通过Spring AOP实现在调用方法前后进行额外的处理 作用 捕获代码中所有的异常让前端得到更详细的业务报错信息屏蔽掉项目框架本身的异常不暴露服务器的内部状态集中处理比如还可以做记录日志 import com.leovany.usercenter.common.ResultVO; import com.leovany.usercenter.common.ErrorCode; import com.leovany.usercenter.common.ResultUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice;/*** 全局异常处理类*/ RestControllerAdvice Slf4j public class GlobalExceptionHandler {/*** 处理异常-BusinessException* param e* return*/ExceptionHandler(BusinessException.class)public ResultVO? businessExceptionHandler(BusinessException e){log.error(businessException: e.getMessage(),e);return ResultUtils.error(e.getCode(),e.getMessage(),e.getDescription());}/*** 处理异常-RuntimeException* param e* return*/ExceptionHandler(RuntimeException.class)public ResultVO? runtimeExceptionHandler(RuntimeException e){log.error(runtimeException: e);return ResultUtils.error(ErrorCode.ERROR_SYSTEM,e.getMessage());} } 4 使用 ​ throw new BusinessException可以在方法中任意地方抛出很方便 示例代码 PostMapping(/login) public ResultVOUser userLogin(RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request) {String userAccount userLoginRequest.getUserAccount();String userPassword userLoginRequest.getUserPassword();if (StringUtils.isAnyBlank(userAccount, userPassword)) {throw new BusinessException(ErrorCode.ERROR_PARAMS);}User user userService.doLogin(userAccount, userPassword, request);return ResultUtils.success(user); }代码对比 5 前端请求效果 总结 ​ 通过封装全局异常处理对异常信息做了统一处理让前端得到更详细的业务信息同时保证系统的安全性不会暴露系统内部信息在代码上对参数校验等方面提供更加方便的形式。
http://www.hkea.cn/news/14406189/

相关文章:

  • 发不了软文的网站怎么做关键词优化南宁手机企业网站定制公司
  • 西安网站建设维护搜索引擎网站推广法 怎么做
  • 电子商务网站开发 ppt资讯网站模板
  • 高端网站开发成本小学生做电子小报的网站
  • 用wordpress 建网站廊坊网站建设
  • 做网站的照片要多大像素保定建站模板搭建
  • 网站建设意向表优化seo是什么意思
  • 域名转移 网站访问万网搜
  • 深圳网站制作工具如何制作小程序商城
  • 谷歌 网站做推广所有免费的网站有哪些
  • 免费做漫画网站模板网站制作服务
  • 网站群 seowordpress 网银
  • 建设论坛网站需要多少钱制作单页网站要网址
  • 高端建站平台设计风格出众个人淘客网站备案
  • 好的免费网站建站平台wordpress超链接下划线
  • 怎样在网站上做办公家具长春市住房和城乡建设局官网
  • 电商网站建设实验心得网站排名怎么上去
  • 北京延庆城乡建设部网站首页在中国可以做国外的域名网站吗
  • 网站设计公司 无锡网站联盟的基本流程
  • 在网站上显示备案信息钢筋网片价格
  • 珠海市网站建设开发公司石家庄园林绿化建设招标网站
  • 卡盟网站怎么做数商云招聘
  • 苏州市建设交易中心网站首页wordpress更知鸟
  • 做文献综述用什么网站怎么自己做网站发优惠券
  • 网站的在线支付模块怎么做网络销售怎样找客户
  • 重庆营销型网站制作广西建设局网站
  • c2c网站代表和网址个人购物网站怎么做
  • 网站建设的入门书籍dedecms做的网站手机上看图片变形
  • 网站 开发合同现在建设网站落后了
  • 沧州网站推广园林景观设计公司客户话术