4.속성 값 설정

리얼브로·2023년 2월 24일
0

thymeleaf

목록 보기
4/10

타임 리프는 HTML5 및 XHTML에서 사용되는 일반적인 속성에 대한 전용 속성을 제공한다.

4-1. th:href

  • href 속성에 th:href 전용 속성을 제공한다.

  • [요청] http://localhost:8080/ch0804/home0101

  • [컨트롤러 메서드]

    @GetMapping("ch0804/home0101")
    public String home0101(Model model){
      return "ch0804/home0101";
    }
  • [뷰 파일]

    <html xmlns:th="http://www.thymeleaf.org">
    <head>
        <title>Home</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    </head>
    <body>
        <h1>Home0101</h1>
        <a href="ch0804/home0201.html" th:href="@{/ch0804/home0201}">Home0201</a>
    </body>
    </html>
  • [응답 화면]

4-2. th:action

  • action 속성에 th:action 전용 속성을 제공한다.

  • [요청] http://localhost:8080/ch0804/home0201

  • [컨트롤러 메서드]

    @GetMapping("ch0804/home0201")
    public String home0201(Model model){
      return "ch0804/home0201";
    }
  • [뷰 파일]

    <html xmlns:th="http://www.thymeleaf.org">
    <head>
        <title>Home</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    </head>
    <body>
        <h1>Home0201</h1>
    
        <form id="board" action="success.html" th:action="@{ch0804/register}" method="POST">
            <table>
                <tr>
                    <td>Title</td>
                    <td><input type="text" name="title"/></td>
                </tr>
            </table>
            <button type="submit" id="btnRegister">Register</button>
        </form>
    </body>
    </html>
  • [응답 화면]

4-3. th:src

  • src 속성에 th:src 전용 속성을 제공한다.

  • [요청] http://localhost:8080/ch0804/home0301

  • [컨트롤러 메서드]

    @GetMapping("ch0804/home0301")
    public String home0301(Model model){
      return "ch0804/home0301";
    }
  • [뷰 파일]

    <html xmlns:th="http://www.thymeleaf.org">
    <head>
        <title>Home</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    </head>
    <body>
        <h1>Home0301</h1>
        <img src="../static/images/player.png" th:src="@{/static/images/player.png}" />
        <img src="../static/images/player.png" th:src="@{../static/images/player.png}" />
        <img src="../../static/images/player.png" />
    
        <img src="../images/player.png" th:src="@{/images/player.png}" />
        <img src="../images/player.png" th:src="@{../images/player.png}" />
        <img src="../../images/player.png" />
    </body>
    </html>
  • [응답 화면]

0개의 댓글