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

中工信融网站建设电子商务网站建设需要什么

中工信融网站建设,电子商务网站建设需要什么,wordpress 4.8 pdf缩略图,免费seo工具大全文章目录 一、什么是自定义异常及全局异常处理#xff1f;二、使用步骤1.创建自定义异常BusinessException2.创建全局异常处理器GlobalExceptionHandler3.通用返回ResponseData4.使用 总结 一、什么是自定义异常及全局异常处理#xff1f; 在web服务中#xff0c;我们的接口… 文章目录 一、什么是自定义异常及全局异常处理二、使用步骤1.创建自定义异常BusinessException2.创建全局异常处理器GlobalExceptionHandler3.通用返回ResponseData4.使用 总结 一、什么是自定义异常及全局异常处理 在web服务中我们的接口通常需要有统一的返回格式而在程序开发过程中不可避免的是需要处理各种异常如果没有全局异常处理器通常我们需要把异常一层层往上抛出最后在controller层处理这样不可避免的需要写大量异常处理的重复代码如何避免这个问题我们可以通过自定义异常结合全局异常处理器实现统一处理。 二、使用步骤 1.创建自定义异常BusinessException 代码如下 package com.uhu.exception;import lombok.Data;/*** author xxx* description 自定义业务异常* create 2023-11-15 09:59**/ Data public class BusinessException extends RuntimeException {private String message;public BusinessException(String message) {super(message);this.message message;}public BusinessException(String message, Throwable cause) {super(message, cause);this.message message;} } 2.创建全局异常处理器GlobalExceptionHandler 代码如下 package com.uhu.exception.handler;import com.uhu.common.ResponseData; import com.uhu.exception.BusinessException; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice;/*** author xxx* description 全局异常处理器* create 2023-11-15 10:10**/ Slf4j RestControllerAdvice public class GlobalExceptionHandler {ExceptionHandler(value Exception.class)public ResponseData exceptionHandler(Exception e) {log.error(GlobalExceptionHandler exceptionHandler error message: {}, e.getMessage(), e);return ResponseData.error(服务器内部错误请联系管理员);}/*** 自定义异常处理* param e* return*/ExceptionHandler(value BusinessException.class)public ResponseData businessExceptionHandler(BusinessException e) {log.error(GlobalExceptionHandler businessExceptionHandler error message: {}, e.getMessage(), e);return ResponseData.error(e.getMessage());} } 3.通用返回ResponseData 代码如下 package com.uhu.common;import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data;import java.io.Serializable;/*** author xxx* description* create 2023-10-01 16:52**/ ApiModel(响应参数) Data public class ResponseDataT implements Serializable {ApiModelProperty(响应码 0-success 500-error)private int code;ApiModelProperty(响应消息)private String message;ApiModelProperty(响应值)private T data;public ResponseData() {this.code 0;this.message success;}public static ResponseData ok(Object obj) {ResponseData responseData new ResponseData();responseData.setData(obj);return responseData;}public static ResponseData ok() {ResponseData responseData new ResponseData();responseData.setMessage(success);return responseData;}public static ResponseData error() {return error(500, error);}public static ResponseData error(String message) {return error(500, message);}public static ResponseData error(int code, String message) {ResponseData responseData new ResponseData();responseData.setCode(code);responseData.setMessage(message);return responseData;} } 4.使用 throw new BusinessException(xxx);总结 以上就是今天要讲的内容本文仅仅简单介绍了SpringBoot实现自定义异常及全局异常处理的使用通过自定义异常及全局异常处理我们可以方便的处理异常。
http://www.pierceye.com/news/555408/

相关文章:

  • js 捕获网站异常插件网站商城怎么做
  • 北辰网站开发淮北哪有做淘宝网站
  • 建设银行e路通网站室内设计师证需要学哪些课程
  • 舟山市建设信息港网站打不开如何建设一个收费的影视图文网站
  • 内蒙建设信息网站网页制作作品阐述
  • 天津网站seo策划服装定制项目计划书
  • 常州网站建设大全买奢侈品代工厂做的产品的网站名
  • 建设网站如入什么费网站建设体会doc
  • 不备案怎么做淘宝客网站吗深圳华强北新闻最新消息今天
  • 梅兰商贸网站开发设计外国网站在中国做推广
  • 有无专门做网站会员人数迅速增加的方法北京单页营销型网站
  • 岳阳网站开发网站运营怎么做建设网站设计
  • 能打开各种网站的浏览器下载合集建设农产品网络营销网站
  • 陕西网站建设方案优化如何做网站挂qq
  • 无锡市网站WordPress分类id在哪
  • 网站建设金网站建设 需求模板
  • 提高网站转化率营销网站制作都选ls15227
  • 一级页面的网站怎么做爱疯卷网站怎么做
  • 网站企业快速备案大气的企业网站
  • 一个好的网站建设微网站手机制作
  • 广州市做民宿什么网站比较好图盛网站建设
  • 深圳做网站佰达科技二十七易语言做网站源码
  • 水禾田网站建设公司南沙区做网站
  • 江西赣州网站上海企业服务云电话
  • 洱源网站建设品牌名字大全
  • 网站建设阶段要做什么帝国cms对比WordPress
  • 盐城做企业网站多少钱网页设计个人总结800
  • 北京做兼职网站温州网站建设模板下载免费
  • 推进门户网站建设方案wordpress插件自动更新
  • 学院网站建设成效做网站需要什么功能