spring boot 配置get方法枚举转换策略
配置转换器
@SuppressWarnings({"rawtypes", "unchecked"})
public class CompositeEnumConverterFactory implements ConverterFactory<String, Enum<?>> {
@Override
public <T extends Enum<?>> Converter<String, T> getConverter(Class<T> targetType) {
return new StringToEnum<>(targetType);
}
}
注入spring容器中
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(WebMvcConfigurer.class)
public class ZbMvcConfig implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverterFactory(new CompositeEnumConverterFactory());
}
}