接口 TypeConverter
- 所有已知实现类:
StandardTypeConverter
public interface TypeConverter
A type converter can convert values between different types encountered during expression evaluation. This is an SPI for the expression parser; seeConversionService
for the primary user API to Spring's conversion facilities.- 从以下版本开始:
- 3.0
- 作者:
- Andy Clement, Juergen Hoeller
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 boolean
canConvert(TypeDescriptor sourceType, TypeDescriptor targetType)
Returntrue
if the type converter can convert the specified type to the desired target type.Object
convertValue(Object value, TypeDescriptor sourceType, TypeDescriptor targetType)
Convert (or coerce) a value from one type to another, for example from aboolean
to aString
.
方法详细资料
canConvert
boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType)
Returntrue
if the type converter can convert the specified type to the desired target type.- 参数:
sourceType
- a type descriptor that describes the source typetargetType
- a type descriptor that describes the requested result type- 返回:
true
if that conversion can be performed
convertValue
Object convertValue(Object value, TypeDescriptor sourceType, TypeDescriptor targetType)
Convert (or coerce) a value from one type to another, for example from aboolean
to aString
.The
TypeDescriptor
parameters enable support for typed collections: A caller may prefer aList<Integer>
, for example, rather than simply anyList
.- 参数:
value
- the value to be convertedsourceType
- a type descriptor that supplies extra information about the source objecttargetType
- a type descriptor that supplies extra information about the requested result type- 返回:
- the converted value
- 抛出:
EvaluationException
- if conversion failed or is not possible to begin with