Spring/Thymeleaf

th:href 예제

YoonJong 2022. 9. 13. 15:05
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
반응형