게시글의 수정 파트를 제작하기 위해 아래와 같이 코드를 작성하였을 때,
<div class="board-body">
<span class="board-body-title">제목</span>
<span id="board-input-title"> <input name="recommendTitle"
th:value="${post.getRecommendTitle()}"
th:field="*{recommendTitle}"
th:placeholder="|제목을 입력해주세요(100자 이내)|"/></span>
</div>
다음과 같이 value 명령이 진행되지 않고, 계속해서 placeholder의 값만 화면에 등장하였다.
th:field의 값을 제거하고 나서야, 원하는 값이 반환되기 시작했는데
th:field는 HTML 태그의 id, name, value 속성을 자동으로 매핑시켜주는 역할을 하므로 value의 값을 무시하게 되는 것입니다.
결과
<div class="board-body">
<span class="board-body-title">제목</span>
<span id="board-input-title"> <input name="recommendTitle"
th:value="${post.getRecommendTitle()}"
th:placeholder="|제목을 입력해주세요(100자 이내)|"/></span>
</div>
참조
Tutorial: Thymeleaf + Spring
Preface This tutorial explains how Thymeleaf can be integrated with the Spring Framework, especially (but not only) Spring MVC. Note that Thymeleaf has integrations for both versions 3.x and 4.x of the Spring Framework, provided by two separate libraries c
www.thymeleaf.org
Thymeleaf th:field overwrites th:value
I just figured out that the th:field attribute overrides the th:value attribute. In my th:each I want to override the value that th:field generates for me. Does anyone know how to achieve this? T...
stackoverflow.com
'Server > Spring&Spring Boot' 카테고리의 다른 글
[Spring colud] open feign 사용법 (0) | 2023.02.25 |
---|---|
[Thymeleaf] th:object, th:field 사용법 (0) | 2023.02.21 |
[Thymeleaf] @태그 안에 $태그 사용하기, Expression preprocessing(전처리) "__"(밑줄 2개) (0) | 2023.02.09 |
[Spring Boot] Spring에서 AWS S3에 파일 삭제 요청 보내기 (0) | 2023.02.07 |
[Spring Boot] Spring Banner 변경해보기 (Spring boot run!) (2) | 2023.02.01 |