2023-09-16
方式一
springmvc.xml
<!--配置异常处理器--> <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="java.lang.ArithmeticException">error</prop> </props> </property> <!--设置共享在请求域中的异常信息的属性名--> <property name="exceptionAttribute" value="ex"></property> </bean>
方式二
ExceptionController
package com.hh.controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; /** * @author hh * @version 1.0 * @DATE 2023-09-16 11:33:32 */ @ControllerAdvice public class ExceptionController { @ExceptionHandler(ArithmeticException.class) public String handleException(Throwable ex, Model model){ model.addAttribute("ex",ex); return "error"; } }
标签:控制器,springmvc,配置,springframework,ex,org,import From: https://www.cnblogs.com/isDaHua/p/17706510.html