通过定义异常类返回异常页面
@Controller
public class Testcontroller {
@RequestMapping("/index")
public String index(){
int i = 1/0;
return "index";
}
}
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ControllerAdvice
public class DealException {
@ExceptionHandler(value = Exception.class)
public String toPage(){
return "error";
}
}