Java 學習記錄134 — 員工管理系統專案練習-Creating Custom Business Exception

src/main/java/exception 新增檔案 ResourceNotFoundException.java

package exception;import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends RuntimeException {
public static final long serialVersionUID = 1L;
public ResourceNotFoundException(String message) {
super(message);
}
}

若數據庫查不到資料的話,就可以使用自定義Exception

返回給客戶端對應的狀態 HttpStatus.NOT_FOUND

--

--

記錄成為軟體工程師的過程

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store