如何添加我的转换器(StringToMYTypeConverter)以供(所有,而不仅仅是一个)控制器使用?
public class StringToMYTypeConverter
implements Converter<String, MYType> {
@Override
public MYType convert(String from) {
MYType myType = ... // do conversion
return myType;
}
}
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new StringToEmployeeConverter());
}
}