配置转换器
@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());
}
}
标签:get,spring,boot,public,Override,new,class
From: https://www.cnblogs.com/huisunan/p/17914386.html