Thymeleaf(parameter, utext)

2024. 6. 14. 18:54JSP+Spring Boot

요청 위임된 request에 존재하는 파라미터 출력하기
        ${param.key}
        - request에 존재하는 parameter(매개변수) 값 얻어와 출력

<form action="/example/ex2" method="post">
<h4>타임리프 예제 2</h4>
이름 : <input type="text" name="inputName"><br>
나이 : <input type="number" name="inputAge"><br>
색상 : 
Red : <input type="checkbox" name="color" value="Red">
Blue : <input type="checkbox" name="color" value="Blue">
Green : <input type="checkbox" name="color" value="Green">
<button>제출하기</button>
<br>
</form>

 

<ul>
    <li th:text="${param.inputName}">제출된 이름</li>
    <li th:text="${param.inputAge}">제출된 나이</li>        
    <!-- 같은 name 속성 값을 가진 파라미터는 배열로 전달 -->

    <li th:text="${param.color}">체크된 색상</li>
    <!-- color로 전달받은 값이 없으면 null = 빈 칸으로 보이게 됨
    반복해야될 값이 없으면 반복을 안할뿐, 에러가 보이지 않음
     -->
</ul>

 

 

값 입력

 

결과

 

 

 

th:text / th:utext

ExampleController 에 작성한 <h1>테스트 중 &times;</h1> 이 innerHTML임

th:text = "속성값"
    - 해당 태그에 "속성값"을 내용으로 출력
    - 단, html 태그, 특수문자 해석 불가능(innerHTML)

th:utext = "속성값"
- 해당 태그에 "속성값"을 내용으로 출력
- 단, html 태그, 특수문자 해석 가능(innerHTML)

 

<div>
    <h4>th:text(HTML 태그 해석 x)</h4>
    <th:block th:text="${str}">str</th:block>
    <!-- 이 태그는 h1 자체도 하나의 글자로 표현 
        h1이 그대로 사용자 화면에 보여짐
    -->
</div>
<div>
    <h4>th:text(HTML 태그 해석 o)</h4>
    <th:block th:utext="${str}">str</th:block>
    <!-- 이 태그는 h1 태그를 사용해서 작성이 가능 
        태그들을 모두 읽고, 읽은 표현 내용이 사용자 화면에 보여짐
    -->
</div>

 

 

text / utext

'JSP+Spring Boot' 카테고리의 다른 글

Thymeleaf(switch, case)  (0) 2024.06.14
Thymeleaf (if, unless)  (0) 2024.06.14
Thymeleaf로 객체 값 얻어오기  (1) 2024.06.14
Thymeleaf(block, text, each)  (0) 2024.06.14
Thymeleaf  (0) 2024.06.14