修改异常处理方式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. 解决The current branch is not configured for pull No value for key branch.master.merge found in config

    使用Git Pull项目的时候出现这个问题: The current branch is not configured for pull No value for key branch.master. ...

  2. Java日志框架解析及实战分析

    转载自: https://zhuanlan.zhihu.com/p/24272450 https://zhuanlan.zhihu.com/p/24275518 作为Java程序员,幸运的是,Java ...

  3. 多线程篇四:ThreadLocal实现线程范围内变量共享

    1.static实现线程范围内变量共享 package com.test.shareData; import java.util.Random; /** * 多线程范围内的数据共享 * @author ...

  4. sql: 生日赠品中的相关算法

    ---2013年10月9日生日,就以2012年9月1日至2013年8月31日計算 (因為係生日月份前兩個月之最後一天為結算日) DECLARE @birthday datetime,@now date ...

  5. 类的方法练习——定义MySQL类

    要求: 1.对象有id.host.port三个属性 2.定义工具create_id,在实例化时为每个对象随机生成id,保证id唯一 3.提供两种实例化方式,方式一:用户传入host和port 方式二: ...

  6. URL工具类

    UrlUtils = { /** * 判断url是否存在(存在跨域问题) * @param {String} url */ isTrueUrl: function(_url) { result = f ...

  7. IoT Architecture

  8. Linux CentOS如何汉化系统

    su root切换为root用户 写入环境变量 echo "export LANG="zh_CN.UTF8"">>/etc/profile sour ...

  9. android launcher

    1.android_launcher的源码详细分析 2.android---launcher 3.Android 4.4 Launcher3桌面源码分析 4.通过深度剖析Android之Launche ...

  10. Android studio 配置使用maven

    安装nexus(略) 启动nexus 打开web(admin;admin123) http://127.0.0.1:8081/nexus 创建的demo 1 2 3 对应的本地目录 配置maven / ...