
이 글은 2026년 04월 29일 작성된 글입니다.
오늘은 JPA 연관관계 심화, LAZY/EAGER, 그리고 Thymeleaf 기반 화면 구성까지 정리했다.
Answer answer = new Answer();
answer.setContent("답변");
answer.setQuestion(question);
answerRepository.save(answer);
question.addAnswer("답변");
👉 엔티티 내부 메서드로 처리하는 게 더 깔끔함
👉 더티체킹 + cascade 조합
👉 실무 = 대부분 LAZY
private List<Answer> answers = new ArrayList<>();
👉 직접 만들 필요 없음
👉 유지보수 쉬워짐
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
model.addAttribute("questionList", list);
th:text
th:each
th:if
th:href
👉 JSP보다 훨씬 깔끔
<tr th:each="q : ${questionList}">
<td th:text="${q.subject}"></td>
</tr>
<h1 th:text="${question.subject}"></h1>
<a th:href="@{|/question/detail/${question.id}|}">
👉 path variable 방식