Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

yj factory

[Spring] @ModelAttribute 사용시 Date 날짜형 처리 본문

Spring

[Spring] @ModelAttribute 사용시 Date 날짜형 처리

yjseo 2016. 2. 2. 13:15

@ModelAttribute를 사용해 파라미터값들을 받을때 Date형의 input값이 비어있으면 오류가 발생한다.

컨트롤러 클래스 상단에 다음과 같이 소스를 넣어주어 해결한다.

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