#thymeleaf #타임리프 #문법정리

mrbang-00·2022년 5월 25일
1
post-thumbnail

😜타임리프란?

thymeleaf는 자바 라이브러리이면서 웹, 웹이 아닌 환경에서 html, xml, javascript, css, 텍스트를 생성할수 있는 템플릿 엔진이라고 한다.

기존 java에서는 jsp라는 java server page라는 곳에서 jstl(java standard library)라는 라이브러리를 통해서 앞단과 뒷단데이터를 가져다 사용을 하였다.

하지만 Spring에서는 thymeleaf를 권장하고 있다.

타임리프 문법 예제

🧨데이터를 가져올때

let sessionval = /*[[${session.sessionstate}]]*/ "";
  • map이나 session과 같은 객체에 담은 값을 가져올때
<option th:each="item : ${datalist}" th:value="|${item.num}_${item.name}|" th:utext="${item.name}"></option>
<option th:each="item : ${list에담은값}" th:value="|${item.num}_${item.name}|" th:utext="${item.name}"></option>
  • list형태 데이터를 가져올때

위형식으로 호출을 하게되면 java단에서 세션에 담은 객체를 가져올수 있다. 뒤에"" 이런형태로 명시를 해야 해당 세션값을 자바스크립트에서 "세션값" 이런형태로 가져올수 있다.

🧨 문법 예제

<button th:href="@{/logout}" type="button" th:id="logout_id" th:class="logout_id" title="로그아웃">로그아웃</button>코드를 입력하세요
  • href경로를 지정해줄때 th:href="@{/경로}"
  • id값을 명시할때 th:id="아이디명"
  • class값을 명시할때 th:class="클래스명"
<option th:each="item : ${datalist}" th:value="|${item.num}_${item.name}|" th:utext="${item.name}"></option>
  • value값을 합쳐서 사용할때 th:value="|{값1}_{값2}|"
  • text값 th:utext="${텍스트값}"
<a data-toggle="modal" th:onclick="|javascript:modalfun("A")|" data-target="#modalid">onclick이벤트</a>
  • onclick이벤트 : th:onclick="|javascript:함수명(매개변수)|"
profile
공부란 인생을 고화질로 보는것 https://linktr.ee/mrbang_00

0개의 댓글