본문 바로가기
Spring/Thymeleaf

th:href 예제

by YoonJong 2022. 9. 13.
728x90

타임리프에서는 링크를 처리하는 문법으로 th:href를 사용한다.

 

@GetMapping("/ex05")
public String thymeleafExample05() {
    return "thymeleafEx/thymeleafEx05";
}

 

아래와 같이 상대경로와 절대경로로 표현할 수 있다.

<a> 태그를 사용하여 th:href="@{ }" 안에 경로를 넣어준다

<div>
    <a th:href="@{/thymeleaf/ex01}">예제 1페이지 이동</a>
</div>
<div>
    <a th:href="@{https://www.thymeleaf.org/}">thymeleaf 공식 홈페이지 이동</a>
</div>

 

 

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>Thymeleaf 링크처리 예제 페이지</h1>
    <div>
        <a th:href="@{/thymeleaf/ex01}">예제 1페이지 이동</a>
    </div>
    <div>
        <a th:href="@{https://www.thymeleaf.org/}">thymeleaf 공식 홈페이지 이동</a>
    </div>


</body>
</html>

 

결과

 

728x90

'Spring > Thymeleaf' 카테고리의 다른 글

Thymeleaf 페이지 레이아웃  (0) 2022.09.14
th:switch & th:case 예제  (0) 2022.09.13
th:if & th:unless 예제  (0) 2022.09.13
th:each 예제  (0) 2022.09.13
th:text 예제  (0) 2022.09.13

댓글