局部异常处理的方法:
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/demo")
public class DemoController {
/**
* 局部异常处理
* 只能处理当前控制器出现的异常
* @return
*/
@ExceptionHandler(value = {Exception.class})
public String HandlerException(){
System.out.println("DemoController出现异常");
return "errorPage";
}
@RequestMapping("/test1")
public String test1(){
System.out.println("test1方法。。。");
return "page";
}
}
打印异常信息:
/**
* 展示异常
* @param exception 异常信息
* @return
*/
@ExceptionHandler(value = {Exception.class})
public String HandlerExceptio