All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pighand.framework.spring.converter.StringToEnumConverterFactory Maven / Gradle / Ivy

package com.pighand.framework.spring.converter;

import com.pighand.framework.spring.base.BaseEnum;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * 字符串转枚举工厂
 * 

* add {@code registry.addConverterFactory(new StringToEnumConverterFactory());} to WebMvcConfig */ public class StringToEnumConverterFactory implements ConverterFactory { private static final Map CONVERTERS = new HashMap<>(); /** * 获取一个从 String 转化为 T 的转换器,T 是一个泛型,有多个实现 * * @param targetType 转换后的类型 * @return 返回一个转化器 */ @Override public Converter getConverter(Class targetType) { Converter converter = CONVERTERS.get(targetType); if (converter == null) { converter = new StringToEnumConverter<>(targetType); CONVERTERS.put(targetType, converter); } return converter; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy