상세 컨텐츠

본문 제목

[Spring] form에서 날짜 값을 받을때 typeMisMatch 오류 해결방법

헉!!/jsp, java

by 권태성 2015. 7. 17. 18:50

본문

날짜를 bean(vo)에 매핑할때 form에 입력된 날짜는 String형인데 bean의 날짜변수 타입은 Date 타입이라면 typeMisMatch 오류가 발생합니다.

이를 해결하기 위해서는 InitBinder를 사용하면 간단하게 해결이 됩니다.

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

컨트롤러 상단에 위의 initBinder 소스를 넣어주면 됩니다.



관련글 더보기