thymeleaf 문법정리

이진섭·2022년 11월 24일
0

Spring_boot

목록 보기
10/16

타임리프 의존성 추가

implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

타임리프 적용할 html에 태그 추가하기

타임리프의 th속성을 사용하기 위해 추가
순수 html파일의 경우 알아서 자동으로 controller랑 연결

<html lang="en" xmlns:th="http://www.thymeleaf.org">

thymeleaf 문법정리

기본기능

  • 가본적으로 ${} 표현식을 사용하여 데이터 접근
<h2 th:text="${data}">Hello World<h2>

th:href="@{}"

  • 클릭시 해당 url로 이동
<body>
  <h2>
    <a th:href="@{|/question/detail/${question.id}|}"></a>
  </h2>
</body>

th:value="${}"

  • input의 value에 값 넣을때, 여러개는 + 추가
<input type="text" id="userId" th:value="${userId} + '의 이름은 ${userName}"/>
profile
하루하루성장하기

0개의 댓글