package org.tukorea.web.exception;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.http.HttpStatus;
@Component
@ControllerAdvice
public class MemberControllerAdvice {
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public String handleException(Exception e) {
e.printStackTrace();
return "member/error";
}
@ExceptionHandler(DataNotFoundException.class)
public String handlerException(DataNotFoundException e) {
e.printStackTrace();
return "member/not_found";
}
}
package org.tukorea.web.exception;
public class DataNotFoundException extends Exception {
private static final long serialVersionUID = 1000L;
public DataNotFoundException() {
}
public DataNotFoundException(String msg) {
super(msg);
}
public DataNotFoundException(Throwable th) {
super(th);
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DataNotFoundException</title>
</head>
<body>
<h1>DataNotFoundException</h1>
<c:url value="/member/list" var="url"/>
<a href="${url}">학생목록 화면가기</a>
</body>
</html>