이 내 HTML 양식입니다 :날짜는 항상 null 전송
<form ui-jp="parsley" th:action="@{/users/created}" th:object="${userCreateDto}" method="post">
<div class="row m-b">
<div class="col-sm-6">
<div class="form-group">
<label>User Valid From</label>
<input type='date' class="form-control" th:field="*{validFrom}" required/>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>User Valid To</label>
<input type='date' class="form-control" th:field="*{validTill}" required/>
</div>
</div>
</div>
</form>
이 컨트롤러 :
@RequestMapping(value = "/created", method = RequestMethod.POST)
public String processCreateUsers(@ModelAttribute UserCreateDto userCreateDto, BindingResult error) {
log.info("Creating users with this input :"+ userCreateDto.toString());
this.userService.createUser(userCreateDto);
return "redirect:/users";
}
그리고 이것은
public class UserCreateDto {
private String username;
private String firstName;
private String lastName;
private String password;
@DateTimeFormat(pattern = "yyyy-mm-dd")
private Date validFrom;
@DateTimeFormat(pattern = "yyyy-mm-dd")
private Date validTill;
}
여기에 DTO이다 날짜가 자바입니다 .sql.Date
또한 가져올 때 내가 사용자 배열을 가지고있는 JSON 파일을 통해이 작업을 성공적으로 수행 할 수 있습니다.
뷰를 통해 실행하면 validFrom
및 validTill
의 값이 null로 표시됩니다.
또한 제출을 클릭 한 후 양식 데이터를 확인하면 필요한 모든 입력이 올바르게 설정됩니다. 이벤트에 Date 매개 변수가 설정됩니다.
Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Date' for property 'validFrom'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.format.annotation.DateTimeFormat java.sql.Date] for value '2017-12-10'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.joda.time.DateTime] to type [@org.springframework.format.annotation.DateTimeFormat java.sql.Date]
나는 여기에 놓치고 무엇 : 나는 BindingResult 오류를 인쇄 할 때
이 무엇입니까?
참고 : java.util.Date works!
'BindingResult error'를 출력하면 어떻게됩니까? – holmis83
질문에 추가했습니다. – nirvair