java中自定义Locale转换器

import java.util.Locale;
import java.util.Map;

public class LocaleConverter extends ognl.DefaultTypeConverter {
   @Override
    public Object convertValue(Map context, Object value, Class toType) {
        if (toType == Locale. class ) {
           String locale = ((String[]) value)[ 0 ];
            return new Locale(locale.substring( 0 , 2 ), locale.substring( 3 ));
       } else if (toType == String. class ) {
           Locale locale = (Locale) value;
            return locale.toString();
       }
        return null ;
   }
}

你可能感兴趣的:(java)