2017-02-21 1 views
0

날짜를 보낼 때 Thymeleaf 날짜 형식에 문제가 있습니다. html로는 .... 올바르게 H3 태그 내에서가 아니라 날짜 선택기의 코드 안에 내가 왜 이해할 수없는 날짜를 보여준다는 하나의 시간과 날짜를 표시하는 이유Thymeleaf 날짜 형식의 th : 값 표시 방법?

<div> 
 
<label for="birthdate" th:text="#{editprofile.about4.birthdate}">Birth date</label> 
 
<label class="input"> 
 
<i class="icon-append fa fa-calendar"></i> 
 
<input type="date" name="date" id="birthdate" class="form-control margin-bottom-20" th:value="${#dates.format(profile2about2th.birthdate,'yyyy/MM/dd')}" th:field="*{birthdate}"> 
 
</input> 
 
</label> 
 
<h3 th:text="${#dates.format(profile2about2th.birthdate,'yyyy/MM/dd')}"></h3> 
 
</div>

입력란 = "날짜"name = "생년월일"id = "생년월일"class = "form-control margin-bottom-20"value = "1932-10-10 00 : 00 : 00.0 "

enter image description here

감사합니다.

답변

0

th:fieldth:value을 동일한 태그에 사용하지 마십시오. (th:fieldname, idvalue 태그가있는 태그의 특성을 설정합니다. th:field을 중단했지만 양식이 올바르게 제출되지 않으면 올바른 형식을 갖게됩니다.

이 같은 컨트롤러에 InitBinder 방법을 추가 : 내 생각에,이 문제를 해결하는 방법은하는 것입니다

@Controller 
public class WhateverController { 
    . 
    . 
    . 

    @InitBinder 
    public void initBinder (WebDataBinder binder) { 
     binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy/MM/dd"), true)); 
    } 

    . 
    . 
    . 
} 

는 일을 제거 값입니다. 귀하의 HTML은 다음과 같아야합니다

<div> 
    <label for="birthdate" th:text="#{editprofile.about4.birthdate}">Birth date</label> 
    <label class="input"> 
     <i class="icon-append fa fa-calendar"></i> 
     <input type="date" name="date" id="birthdate" class="form-control margin-bottom-20" th:field="*{birthdate}" /> 
    </label> 

    <h3 th:text="${#dates.format(profile2about2th.birthdate,'yyyy/MM/dd')}"></h3> 
</div> 

당신이 당신의 전체 응용 프로그램에 대해 작동하지 그냥 하나의 컨트롤러하려는 경우뿐만 아니라 글로벌 바인더를 추가하는 방법이 있습니다.

+0

안녕하세요, 많이 감사합니다. 순수한 Thymeleaf를위한 해결책이 있습니까? 컨트롤러에서하지 않으면된다는 뜻인가요? (그래서 내가 포럼에서도 물었습니다.) – Mike

+0

'th : field = "* {birthdate}"'(POST 된 값을 자바 날짜로 다시 변환 시키십시오) 사용하려면 컨트롤러에서해야합니다. – Metroids

관련 문제