2.텍스트 사용

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

thymeleaf

목록 보기
2/10

2-1. th:text

  • 이스케이프한 값을 표시한다.

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

  • [컨트롤러 메서드]

    \src\main\java\org.brolab.thymeleaf\Ch0802_Controller.java

    @GetMapping("ch0802/home0101")
    public String home0101(Model model){
      model.addAttribute("msg","<b>Hello world!</b>");
      return "ch0802/home0101";
    }
  • [뷰 파일]

    \src\main\resources\templates\ch0802\home0101.html

    <html xmlns:th="http://www.thymeleaf.org">
    <head>
        <title>Home</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    </head>
    <body>
        <p th:text="${msg}">greeting</p>
    </body>
    </html>
  • [응답화면]

2-2. th:utext

  • HTML 태그가 적용된 형태로 표시한다.

  • [요청] http://localhost:8080/ch0802/home0102

  • [컨트롤러 메서드]

    \src\main\java\org.brolab.thymeleaf\Ch0802_Controller.java

    @GetMapping("ch0802/home0102")
    public String home0102(Model model){
      model.addAttribute("msg","<b>Hello world!</b>");
      return "ch0802/home0102";
    }
  • [뷰 파일]

    \src\main\resources\templates\ch0802\home0102.html

    <html xmlns:th="http://www.thymeleaf.org">
    <head>
        <title>Home</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    </head>
    <body>
        <p th:utext="${msg}">greeting</p>
    </body>
    </html>
  • [응답화면]

2-3.th:value

  • HTML 요소 값

    <html xmlns:th="http://www.thymeleaf.org">
    <head>
        <title>Home</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    </head>
    <body>
        <input type="text" th:value="${msg}">
    </body>
    </html>

0개의 댓글