如何在WebMVCConfigureAdapter中使用addFormatters @配置 @启用WebMVC// 公共类WebApplicationConfig扩展了WebMVCConfigureAdapter{ @凌驾 公共void addFormatters(FormatterRegistry注册表){ addConverter(新的EmailConverter()); } }

如何在WebMVCConfigureAdapter中使用addFormatters @配置 @启用WebMVC// 公共类WebApplicationConfig扩展了WebMVCConfigureAdapter{ @凌驾 公共void addFormatters(FormatterRegistry注册表){ addConverter(新的EmailConverter()); } },converter,formatter,Converter,Formatter,我在FormatterRegistry中添加了一个转换器,但我不知道如何使用它,有人能帮我吗?当我们在@Configuration类中使用@EnableWebMvc注释时, 它使用WebMvcConfigurationSupport作为默认的SpringMVC配置文件 其中包含以下配置: @Configuration @EnableWebMvc // <mvc:annotation-driven /> public class WebApplicationConfig extends

我在
FormatterRegistry
中添加了一个
转换器
,但我不知道如何使用它,有人能帮我吗?

当我们在
@Configuration
类中使用
@EnableWebMvc
注释时, 它使用
WebMvcConfigurationSupport
作为默认的SpringMVC配置文件

其中包含以下配置:

@Configuration
@EnableWebMvc // <mvc:annotation-driven />
public class WebApplicationConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new EmailConverter());
    }
}
因此,当我们重写
addFormatters
并添加自定义转换器(如
EmailConverter
)时,我们可以这样使用:

@Bean
public FormattingConversionService mvcConversionService() {
    FormattingConversionService conversionService = new DefaultFormattingConversionService();
    addFormatters(conversionService);
    return conversionService;
}

当我们在
@配置
类中使用
@EnableWebMvc
注释时, 它使用
WebMvcConfigurationSupport
作为默认的SpringMVC配置文件

其中包含以下配置:

@Configuration
@EnableWebMvc // <mvc:annotation-driven />
public class WebApplicationConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new EmailConverter());
    }
}
因此,当我们重写
addFormatters
并添加自定义转换器(如
EmailConverter
)时,我们可以这样使用:

@Bean
public FormattingConversionService mvcConversionService() {
    FormattingConversionService conversionService = new DefaultFormattingConversionService();
    addFormatters(conversionService);
    return conversionService;
}