修改异常处理方法3中的全局异常处理Controller便可html
package bjsxt.exception; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver; import java.util.Properties; /** * Created by Administrator on 2019/2/14. * 全局异常处理类,使用SimpleMappingExceptionResolver 作全局异常处理 * 优势:直接在一个方法里对须要处理的异常跳转不一样的视图,比较简单方便 * 缺点:没法把错误信息传递到视图层 */ @Configuration public class GlobalException { /** * * @return */ @Bean public SimpleMappingExceptionResolver getSimpleMappingExceptionResolver(){ SimpleMappingExceptionResolver resolver=new SimpleMappingExceptionResolver(); Properties properties=new Properties(); /** * 参数一:异常的类型,注意必须是异常类型的全名 * 参数二:视图名称 */ properties.put("java.lang.ArithmeticException","error_arithmetic"); properties.put("java.lang.NullPointerException","error_nullPointer"); resolver.setExceptionMappings(properties); return resolver; } }