Error
Spring - 'Failed to convert from type [java.lang.String] to type [java.util.Date] for value [ ]'
Dlise
2024. 5. 5. 21:57
회원가입을 할 때 생일을 입력받으려고 하는데 다음 오류가 발생했다.
Failed to convert from type [java.lang.String] to type [java.util.Date] for value [2024-05-01]
데이터 타입이 달라서 문제라는 점은 바로 알겠는데 어떻게 해결해야 하는지를 몰라서 찾아보았다.
해결 방법
Failed to convert property value of type java.lang.String to required type java.util.Date
I'm getting this error when I try to input a date in a form. TaskController @RequestMapping(value = "/docreatetask", method = RequestMethod.POST) public String doCreateTask(Model model, @Valid Task
stackoverflow.com
위 페이지를 통해 해결할 수 있었다.
DTO에서 birthday 변수에 @DateTimeFormat 어노데이션을 붙이면 된다.
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date userBirthday;
무난히 해결!