πŸ“ GitHub λ°”λ‘œκ°€κΈ°
πŸ“ Debug Issue λ°”λ‘œκ°€κΈ°

Error

🚨 PropertyValueException : not-null property references a null or trasient value


원인

  • nullable = false둜 ν‘œμ‹œλœ ν•„λ“œ β†’ null 값을 μ €μž₯ν•  λ•Œ λ°œμƒν•˜λŠ” Error

    • β‘  Dto : μ •μƒμ μœΌλ‘œ ν•„λ“œ λ‘κ°œ μ„ μ–Έλ˜μ–΄ 있음 βœ…
    • β‘‘ Entity : μ •μƒμ μœΌλ‘œ μƒμ„±μž Annotation μ„ μ–Έλ˜μ–΄ 있음 βœ…
    • β‘’ Service : μ •μƒμ μœΌλ‘œ Repository 객체 생성 βœ…
// Memo μƒμ„±ν•˜κΈ°
    @PostMapping("/api/memos")
    public Memo createMemo(MemoRequestDto memoRequestDto) {
        return memoService.createMemo(memoRequestDto);
    }
  • Controller의 createMemo λ©”μ„œλ“œ νŒŒλΌλ―Έν„°μ— @RequestBody Annotation λˆ„λ½ πŸ”₯
    β†’ λ•Œλ¬Έμ— Service단에 Dto 값이 μ „λ‹¬λ˜μ§€ μ•Šμ€μ±„λ‘œ DB생성이 λ˜μ–΄,
    null Errorκ°€ λ‚¬λ˜ 것 ❗️

ν•΄κ²°

1️⃣ @RequestBody

  • Body에 μ „λ‹¬λ˜λŠ” 데이터 β†’ λ©”μ„œλ“œ 인자(객체)와 λ§€μΉ­ν•˜μ—¬ 데이터λ₯Ό λ°›μ•„ μ²˜λ¦¬ν•  수 μžˆλŠ” Annotation

  • Clientκ°€ λ³΄λ‚΄λŠ” HTTP Request λ³Έλ¬Έ(JSON) β†’ Java Object둜 λ³€ν™˜

  • Client μž…λ ₯κ°’ β†’ HTTP Body에 Json ν˜•νƒœλ‘œ λ„˜μ–΄κ°
    β†’ νŒŒλΌλ―Έν„°μ— @RequestBody + 값을 λ°›μ•„μ˜¬ 객체 지정

2️⃣ 디버깅 ν›„

profile
🐱Sunyeon-Jeong, mallang developer🐰

1개의 λŒ“κΈ€

comment-user-thumbnail
2023λ…„ 8μ›” 4일

μœ μ΅ν•œ 자료 κ°μ‚¬ν•©λ‹ˆλ‹€.

λ‹΅κΈ€ 달기