티스토리 뷰

토이 프로젝트를 하다보면 기본적인 실수를 할때가 있습니다.

컨트롤러에서 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

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함