How to register global databinding for LocalDate in spring mvc?

后端 未结 2 1609
無奈伤痛
無奈伤痛 2020-12-21 09:11

I\'d like to use LocalDate as type in a Servlet created with spring-mvc. The users should be able to provide the date in multiple vali

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-21 09:21

    I still don't know why PropertyEditor does not work. But the following solutions worked.

    @Configuration
    public class LocalDateConfig extends WebMvcConfigurerAdapter {
        @Override
        public void addFormatters(FormatterRegistry registry) {
            super.addFormatters(registry);
            registry.addFormatterForFieldType(LocalDate.class, new Formatter() {
                //override parse() and print()
            });
        }
     }
    

提交回复
热议问题