标签:exception val work import handle style imp pre port
在class注解上@ControllerAdvice,
在方法上注解上@ExceptionHandler(value = Exception.class),具体代码如下:
package me.shijunjie.controller; import javax.servlet.http.HttpServletRequest; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; @ControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(value = Exception.class) public void handleGlobalException(HttpServletRequest req, Exception e) { //打印异常信息: //e.printStackTrace(); System.out.println("GlobalExceptionHandler.handleGlobalException()"); } }
@RequestMapping("/zeroException") public int zeroException(){ return 111/0; }
标签:exception val work import handle style imp pre port
原文地址:http://www.cnblogs.com/s648667069/p/6398696.html