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

揭阳网站设计制作百度后台管理

揭阳网站设计制作,百度后台管理,武安城乡建设网站,代运营服务首先定义一个统一管理所有异常的类,加上注解RestControllerAdvice定义处理不同异常的方法,加上注解 ExceptionHandler RestControllerAdvice public class GlobalExceptionHandler {private static final Logger log LoggerFactory.getLogger(GlobalExc…
  1. 首先定义一个统一管理所有异常的类,加上注解@RestControllerAdvice
  2. 定义处理不同异常的方法,加上注解 @ExceptionHandler
  3. @RestControllerAdvice
    public class GlobalExceptionHandler
    {private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);/*** 权限码异常*/@ExceptionHandler(NotPermissionException.class)public AjaxResult handleNotPermissionException(NotPermissionException e, HttpServletRequest request){String requestURI = request.getRequestURI();log.error("请求地址'{}',权限码校验失败'{}'", requestURI, e.getMessage());return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");}/*** 角色权限异常*/@ExceptionHandler(NotRoleException.class)public AjaxResult handleNotRoleException(NotRoleException e, HttpServletRequest request){String requestURI = request.getRequestURI();log.error("请求地址'{}',角色权限校验失败'{}'", requestURI, e.getMessage());return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");}/*** 请求方式不支持*/@ExceptionHandler(HttpRequestMethodNotSupportedException.class)public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, HttpServletRequest request){String requestURI = request.getRequestURI();log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());return AjaxResult.error(e.getMessage());}/*** 业务异常*/@ExceptionHandler(ServiceException.class)public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request){log.error(e.getMessage(), e);Integer code = e.getCode();return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage());}/*** 请求路径中缺少必需的路径变量*/@ExceptionHandler(MissingPathVariableException.class)public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request){String requestURI = request.getRequestURI();log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e);return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));}/*** 请求参数类型不匹配*/@ExceptionHandler(MethodArgumentTypeMismatchException.class)public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request){String requestURI = request.getRequestURI();String value = Convert.toStr(e.getValue());if (StringUtils.isNotEmpty(value)){value = EscapeUtil.clean(value);}log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), value));}/*** 拦截未知的运行时异常*/@ExceptionHandler(RuntimeException.class)public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request){String requestURI = request.getRequestURI();log.error("请求地址'{}',发生未知异常.", requestURI, e);return AjaxResult.error(e.getMessage());}/*** 系统异常*/@ExceptionHandler(Exception.class)public AjaxResult handleException(Exception e, HttpServletRequest request){String requestURI = request.getRequestURI();log.error("请求地址'{}',发生系统异常.", requestURI, e);return AjaxResult.error(e.getMessage());}/*** 自定义验证异常*/@ExceptionHandler(BindException.class)public AjaxResult handleBindException(BindException e){log.error(e.getMessage(), e);String message = e.getAllErrors().get(0).getDefaultMessage();return AjaxResult.error(message);}/*** 自定义验证异常*/@ExceptionHandler(MethodArgumentNotValidException.class)public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e){log.error(e.getMessage(), e);String message = e.getBindingResult().getFieldError().getDefaultMessage();return AjaxResult.error(message);}/*** 内部认证异常*/@ExceptionHandler(InnerAuthException.class)public AjaxResult handleInnerAuthException(InnerAuthException e){return AjaxResult.error(e.getMessage());}/*** 演示模式异常*/@ExceptionHandler(DemoModeException.class)public AjaxResult handleDemoModeException(DemoModeException e){return AjaxResult.error("演示模式,不允许操作");}
    }

http://www.dtcms.com/wzjs/236064.html

相关文章:

  • 建立企业网站的步骤百度云搜索引擎网站
  • 东莞平台网站建设设计公司商业网站
  • 郑州网站建设排行互联网优化是什么意思
  • 企业信用信息公示系统查询网站seo啥意思
  • 西安网站公司seo自然排名关键词来源的优缺点
  • 高端网站开发成本一键搭建网站工具
  • 网站的架设seo工作前景如何
  • 做淘宝网站的主机怎么联系百度客服人工服务
  • 沈阳网站建设哪家便宜郑州网络推广平台
  • 电子商务网站开发价格微博营销案例
  • 官网网站备案流程北京seo公司公司
  • 网站的域名证书百度官网进入
  • 做网站知识sem是什么显微镜
  • 无锡论坛网站制作网站排名优化怎样做
  • ppt插件 网站百度推广销售员的工作内容
  • 建设网站公司电话号码优化大师绿色版
  • 网站建设程序做哪些手机百度收录提交入口
  • 网站可以微信支付是怎么做的百度推广账户登陆
  • 网站备案要收费吗请简述网络营销的特点
  • wordpress如何实现关键词优化报价推荐
  • 芜湖网站建设全包仅需800元qq关键词排名优化
  • 企业网站的网址有哪些百度霸屏全网推广
  • 智能网站建设找三好科技360免费建站网页链接
  • 辽宁建设工程造价管理网站网站推广的方式有哪些?
  • o2o系统常用的seo工具
  • iis网站怎么做域名绑定淘宝关键词排名优化
  • 建设一个商城网站的成本竞价外包
  • 织梦网站0day漏洞百度指数什么意思
  • 怎样注册自己的网址怎么做神马搜索排名seo
  • 乐清市网站建设设计做个小程序需要花多少钱