티스토리 뷰
Programming/Spring Boot
[Thymeleaf] 컨트롤러에서 model, session으로 값을 뷰로 넘길 때 th:text 사용시 주의점
놀고싶은개발자 2022. 11. 25. 06:05토이 프로젝트를 하다보면 기본적인 실수를 할때가 있습니다.
컨트롤러에서 model.addAttribute(값, "값"); 으로 넘기고
무작정 th:text="${값}" 으로 시도했는데 '이거 왜 안되는거지??' 좌절에 빠지곤 하지요
제가 방금 그랬었습니다 흑흑
해결법은 간단했습니다.
model로 넘긴 경우는 ${param.값},
session으로 넘긴 경우는 ${session.값} 으로 넘기면 되는거였습니다.
공식 문서를 찾아보니 이렇게 하라고 친절히 설명되어 있더라고요 하하 ㅜㅜ
오늘의 교훈 : 코딩하다가 막히면 공식문서를 열심히 읽어보자
저 같이 막히시는 분들을 위해 기록 남겨둡니다.
출처
https://www.thymeleaf.org/doc/articles/springmvcaccessdata.html
Spring MVC and Thymeleaf: how to access data from templates - Thymeleaf
In a typical Spring MVC application, @Controller classes are responsible for preparing a model map with data and selecting a view to be rendered. This model map allows for the complete abstraction of the view technology and, in the case of Thymeleaf, it is
www.thymeleaf.org
'Programming > Spring Boot' 카테고리의 다른 글
스프링 form으로 thymeleaf 활용해서 객체 주고 받기 (0) | 2023.11.10 |
---|---|
예제 프로젝트 하면서 생긴 트러블슈팅 정리 (0) | 2023.03.23 |
[Spring Boot] Hikari JDBC 설정 시 발생하는 에러 해결법 (0) | 2022.03.17 |
[Spring Boot + Thymeleaf] Form 값 넘겨받아 출력하기 (0) | 2022.02.24 |
[Spring] Spring MVC Project 생성 시 발생하는 오류 해결방법 (0) | 2022.02.11 |
댓글