Optional int parameter 'id' is present but cannot be translated into a null value

한지연·2023년 5월 10일
0
post-thumbnail

문제 상황: rest api 만들기 실습 중 id parameter에 null값을 넣을 수 없다고 함

문제 원인: 해당 api 받아오는 부분에 @PathVarible 넣어주는 것을 깜빡함

    @DeleteMapping("/users/{id}")
    public void deleteUser(int id){
        User user = service.deleteById(id);
        if(user == null){
                throw new UserNotFoundException(String.format("ID[%s] not found", id));
        }
    }

해결 방법: 매개변수 앞에 @Pathvariable을 달아준다.

    public void deleteUser(@PathVariable int id){

profile
배우고 활용하는 것을 즐기는 개발자, 한지연입니다!

0개의 댓글