接口 TypeConverter
- 所有已知子接口:
BeanWrapper
,ConfigurablePropertyAccessor
- 所有已知实现类:
AbstractNestablePropertyAccessor
,AbstractPropertyAccessor
,BeanWrapperImpl
,DataBinder
,DirectFieldAccessor
,ExtendedServletRequestDataBinder
,PortletRequestDataBinder
,ServletRequestDataBinder
,SimpleTypeConverter
,TypeConverterSupport
,WebDataBinder
,WebRequestDataBinder
public interface TypeConverter
Interface that defines type conversion methods. Typically (but not necessarily) implemented in conjunction with thePropertyEditorRegistry
interface.Note: Since TypeConverter implementations are typically based on
PropertyEditors
which aren't thread-safe, TypeConverters themselves are not to be considered as thread-safe either.- 从以下版本开始:
- 2.0
- 作者:
- Juergen Hoeller
- 另请参阅:
SimpleTypeConverter
,BeanWrapperImpl
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 <T> T
convertIfNecessary(Object value, Class<T> requiredType)
Convert the value to the required type (if necessary from a String).<T> T
convertIfNecessary(Object value, Class<T> requiredType, Field field)
Convert the value to the required type (if necessary from a String).<T> T
convertIfNecessary(Object value, Class<T> requiredType, MethodParameter methodParam)
Convert the value to the required type (if necessary from a String).
方法详细资料
convertIfNecessary
<T> T convertIfNecessary(Object value, Class<T> requiredType) throws TypeMismatchException
Convert the value to the required type (if necessary from a String).Conversions from String to any type will typically use the
setAsText
method of the PropertyEditor class, or a Spring Converter in a ConversionService.- 参数:
value
- the value to convertrequiredType
- the type we must convert to (ornull
if not known, for example in case of a collection element)- 返回:
- the new value, possibly the result of type conversion
- 抛出:
TypeMismatchException
- if type conversion failed- 另请参阅:
PropertyEditor.setAsText(String)
,PropertyEditor.getValue()
,ConversionService
,Converter
convertIfNecessary
<T> T convertIfNecessary(Object value, Class<T> requiredType, MethodParameter methodParam) throws TypeMismatchException
Convert the value to the required type (if necessary from a String).Conversions from String to any type will typically use the
setAsText
method of the PropertyEditor class, or a Spring Converter in a ConversionService.- 参数:
value
- the value to convertrequiredType
- the type we must convert to (ornull
if not known, for example in case of a collection element)methodParam
- the method parameter that is the target of the conversion (for analysis of generic types; may benull
)- 返回:
- the new value, possibly the result of type conversion
- 抛出:
TypeMismatchException
- if type conversion failed- 另请参阅:
PropertyEditor.setAsText(String)
,PropertyEditor.getValue()
,ConversionService
,Converter
convertIfNecessary
<T> T convertIfNecessary(Object value, Class<T> requiredType, Field field) throws TypeMismatchException
Convert the value to the required type (if necessary from a String).Conversions from String to any type will typically use the
setAsText
method of the PropertyEditor class, or a Spring Converter in a ConversionService.- 参数:
value
- the value to convertrequiredType
- the type we must convert to (ornull
if not known, for example in case of a collection element)field
- the reflective field that is the target of the conversion (for analysis of generic types; may benull
)- 返回:
- the new value, possibly the result of type conversion
- 抛出:
TypeMismatchException
- if type conversion failed- 另请参阅:
PropertyEditor.setAsText(String)
,PropertyEditor.getValue()
,ConversionService
,Converter