드디어 댓글을 작성하면 비동기적으로 필요한 부분만 로딩되게끔 됐다.
아직 자바스크립트 문법을 몰라서 script.js
를 직접 짤 수 없지만 재밌는 경험을 한 것 같다.
카테고리: QnA미션
Ajax를 적용하여, 댓글이 필요한 부분만 업데이트 되게끔 하려 했으나...
아래와 같이 JSON을 읽게 됐다..??!
에러좀 제발 읽자
~~${".qna-comment-slipp-articles"}.prepend(template);~~
$(".qna-comment-slipp-articles").prepend(template);
카테고리: SpringBoot
//TODO. [추후공부] Jackson라이브러리 : Java Object를 JSON으로 변환하거나 JSON을 Java Object로 변환하는데 사용할 수 있는 Java라이브러리
// org.springframework.boot:spring-boot-starter-web에 포함된 내장 라이브러리
// data : RestController를통해 Json으로 리턴한 데이터 ( Answer클래스 안의 Getter멤버 )
카테고리: QnA
RestController로 변경 후, 댓글 작성을 했는데 Json 리턴이 정상적으로 되지 않아 500 서버 에러가 발생한 상황
2021-04-04 23:13:32.992 WARN 20988 --- [io-8080-exec-10] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException:
Could not write JSON: (was java.lang.NullPointerException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: com.codessquad.qna.domain.Answer["question"]->com.codessquad.qna.domain.Question["answers"])]
The stack trace refers to a field in CustomerResponsePage named empty. The problem might be related to the serialization of that field or the result of its getter method.
If you don't need the field in your JSON output, you can use @JsonIgnore to skip it.
무한순환참조 문제
임시방편 @JsonIgnore
Question과 Answer에서 양방향 참조를 하고 있었기 때문.
# Answer.java
@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(name = "fk_answer_to_question"))
@JsonIgnore
private Question question;
---------------------------------------------------------------------
# Question.java
@OneToMany(mappedBy = "question", cascade = CascadeType.ALL)
private List<Answer> answers;