修改异常处理方式4中的全局异常处理controller

package com.bjsxt.exception;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Properties; /**
* Created by Administrator on 2019/2/14.
* 全局异常处理类,通过实现 HandlerExceptionResolver类做全局异常处理
* 优点:相对于方法4可以传递异常信息
*/ @Configuration
public class GlobalException implements HandlerExceptionResolver{ @Override
public ModelAndView resolveException(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse, @Nullable Object o, Exception e) { ModelAndView mv = new ModelAndView();
//判断不同异常类型,做不同视图跳转
if(e instanceof ArithmeticException){
mv.setViewName("error_arithmetic");
}
if(e instanceof NullPointerException){
mv.setViewName("error_nullPointer");
}
mv.addObject("msg", e.toString());
return mv;
}
}

SpringBoot学习15:springboot异常处理方式5(通过实现HandlerExceptionResolver类)的更多相关文章

  1. SpringBoot: 15.异常处理方式5(通过实现HandlerExceptionResolver类)(转)

    修改异常处理方式4中的全局异常处理controller package com.bjsxt.exception; import org.springframework.context.annotati ...

  2. SpringBoot学习(七)-->SpringBoot在web开发中的配置

    SpringBoot在web开发中的配置 Web开发的自动配置类:在Maven Dependencies-->spring-boot-1.5.2.RELEASE.jar-->org.spr ...

  3. SpringBoot学习之SpringBoot执行器

    在以往的分布式开发当中,各个服务节点的监控必不可少.监控包含有很多方面,比如说:内存占用情况,节点是否健康等.在spring-boot会给我们提供相关资源监控叫做spring-boot-actuato ...

  4. SpringBoot学习(八)-->SpringBoot之过滤器、监听器

    本文将直接使用@WebFilter和@WebListener的方式,完成一个Filter 和一个 Listener. 过滤器(Filter)和 监听器(Listener)的注册方法和 Servlet ...

  5. SpringBoot学习(四)-->SpringBoot快速入门,开山篇

    Spring Boot简介 Spring Boot的目的在于创建和启动新的基于Spring框架的项目.Spring Boot会选择最适合的Spring子项目和第三方开源库进行整合.大部分Spring ...

  6. SpringBoot学习(一):SpringBoot入门

    1.Spring Boot 简介 1) 简化Spring应用开发的一个框架: 2) 整个Spring技术栈的一个大整合: 3) J2EE开发的一站式解决方案: 2.微服务 2014,martin fo ...

  7. SpringBoot学习(六)-->SpringBoot的自动配置的原理

    Spring Boot的自动配置的原理 Spring Boot在进行SpringApplication对象实例化时会加载META-INF/spring.factories文件,将该配置文件中的配置载入 ...

  8. SpringBoot学习(五)-->SpringBoot的核心

    SpringBoot的核心 1.入口类和@SpringBootApplication Spring Boot的项目一般都会有*Application的入口类,入口类中会有main方法,这是一个标准的J ...

  9. SpringBoot学习<二>——SpringBoot的默认配置文件application和多环境配置

    一.SpringBoot的默认文件appliction 上一篇文章已经说明,springboot启动会内嵌tomcat,端口也是默认的8080,如果我们想要改变端口如果做呢? 在springboot项 ...

随机推荐

  1. 11、幻灯片:Slides

    /* ---ts----*/ import { Page,Slides } from 'ionic-angular'; import { ViewChild } from '@angular/core ...

  2. 通过js控制层的动态隐藏

    <style type="text/css"> #dv1{ width:1000px; height:1000px; overflow:hidden; display: ...

  3. markdown语法简单总结

    最常用的十个MarkDown语法总结: 标题:只要在这段文字前加 # 号即可 # 一级标题 最大 ## 二级标题 ### 三级标题 无序列表:在文字前加上 - 或 * 有序列表:在文字前加1. 2.  ...

  4. android 短期计划

    http://www.jianshu.com/p/2a9fcf3c11e4 http://www.jianshu.com/p/5f6d79323923 activity启动模式: http://www ...

  5. SQLAlchemy的使用---数据库的创建与连接

    # 1. 导入SQLAlchemy from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Col ...

  6. PHP Primary script unknown 终极解决方法

    相信很多配置php环境的都遇到过这个恼人的问题: 浏览器访问php文件,返回来 File not found 查看/var/log/nginx/error.log ,有 “Primary script ...

  7. WinDbg:栈帧的含义

    转自:http://www.cppblog.com/weiym/archive/2012/06/07/177958.html 栈从高地址向低地址生长, __stcall和__cdecl调用约定都是函数 ...

  8. jQuery替换已存在于元素element上的事件event

    <html><head><script type="text/javascript" src="/jquery/jquery.js" ...

  9. Java IO 整理总结

    read(byte b[], int off, int len) 方法的作用是从输入流中读取 len 个字节,并把数据写入到字节数组b中,并返回实际读取了多少数据.如果没有读取到任何数据,意味着文件已 ...

  10. linux中启动网卡报错:Bringing up interface eth1: Error: Connection activation failed

    在重启linux网络服务的时候提示: Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/2 并且产生报错 ...