类 SimpleEvaluationContext
- java.lang.Object
- org.springframework.expression.spel.support.SimpleEvaluationContext
- 所有已实现的接口:
EvaluationContext
public class SimpleEvaluationContext extends Object implements EvaluationContext
A basic implementation ofEvaluationContext
that focuses on a subset of essential SpEL features and customization options, targeting simple condition evaluation and in particular data binding scenarios.In many cases, the full extent of the SpEL language is not required and should be meaningfully restricted. Examples include but are not limited to data binding expressions, property-based filters, and others. To that effect,
SimpleEvaluationContext
is tailored to support only a subset of the SpEL language syntax, e.g. excluding references to Java types, constructors, and bean references.When creating a
SimpleEvaluationContext
you need to choose the level of support that you need for property access in SpEL expressions:- A custom
PropertyAccessor
(typically not reflection-based), potentially combined with aDataBindingPropertyAccessor
- Data binding properties for read-only access
- Data binding properties for read and write
Conveniently,
forReadOnlyDataBinding()
enables read access to properties viaDataBindingPropertyAccessor
; same forforReadWriteDataBinding()
when write access is needed as well. Alternatively, configure custom accessors viaforPropertyAccessors(org.springframework.expression.PropertyAccessor...)
, and potentially activate method resolution and/or a type converter through the builder.Note that
SimpleEvaluationContext
is typically not configured with a default root object. Instead it is meant to be created once and used repeatedly throughgetValue
calls on a pre-compiledExpression
with both anEvaluationContext
and a root object as arguments:Expression.getValue(EvaluationContext, Object)
.For more power and flexibility, in particular for internal configuration scenarios, consider using
StandardEvaluationContext
instead.- 从以下版本开始:
- 4.3.15
- 作者:
- Rossen Stoyanchev, Juergen Hoeller
- 另请参阅:
forPropertyAccessors(org.springframework.expression.PropertyAccessor...)
,forReadOnlyDataBinding()
,forReadWriteDataBinding()
,StandardEvaluationContext
,StandardTypeConverter
,DataBindingPropertyAccessor
嵌套类概要
嵌套类 修饰符和类型 类 说明 static class
SimpleEvaluationContext.Builder
Builder forSimpleEvaluationContext
.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 static SimpleEvaluationContext.Builder
forPropertyAccessors(PropertyAccessor... accessors)
Create aSimpleEvaluationContext
for the specifiedPropertyAccessor
delegates: typically a customPropertyAccessor
specific to a use case (e.g. attribute resolution in a custom data structure), potentially combined with aDataBindingPropertyAccessor
if property dereferences are needed as well.static SimpleEvaluationContext.Builder
forReadOnlyDataBinding()
Create aSimpleEvaluationContext
for read-only access to public properties viaDataBindingPropertyAccessor
.static SimpleEvaluationContext.Builder
forReadWriteDataBinding()
Create aSimpleEvaluationContext
for read-write access to public properties viaDataBindingPropertyAccessor
.BeanResolver
getBeanResolver()
SimpleEvaluationContext
does not support the use of bean references.List<ConstructorResolver>
getConstructorResolvers()
Return an empty list, always, since this context does not support the use of type references.List<MethodResolver>
getMethodResolvers()
Return the specifiedMethodResolver
delegates, if any.OperatorOverloader
getOperatorOverloader()
Return an instance ofStandardOperatorOverloader
.List<PropertyAccessor>
getPropertyAccessors()
Return the specifiedPropertyAccessor
delegates, if any.TypedValue
getRootObject()
Return the specified root object, if any.TypeComparator
getTypeComparator()
Return an instance ofStandardTypeComparator
.TypeConverter
getTypeConverter()
The configuredTypeConverter
.TypeLocator
getTypeLocator()
SimpleEvaluationContext
does not support use of type references.Object
lookupVariable(String name)
Look up a named variable within this evaluation context.void
setVariable(String name, Object value)
Set a named variable within this evaluation context to a specified value.
方法详细资料
getRootObject
public TypedValue getRootObject()
Return the specified root object, if any.- 指定者:
getRootObject
在接口中EvaluationContext
getPropertyAccessors
public List<PropertyAccessor> getPropertyAccessors()
Return the specifiedPropertyAccessor
delegates, if any.
getConstructorResolvers
public List<ConstructorResolver> getConstructorResolvers()
Return an empty list, always, since this context does not support the use of type references.- 指定者:
getConstructorResolvers
在接口中EvaluationContext
getMethodResolvers
public List<MethodResolver> getMethodResolvers()
Return the specifiedMethodResolver
delegates, if any.
getBeanResolver
public BeanResolver getBeanResolver()
SimpleEvaluationContext
does not support the use of bean references.- 指定者:
getBeanResolver
在接口中EvaluationContext
- 返回:
- always
null
getTypeLocator
public TypeLocator getTypeLocator()
SimpleEvaluationContext
does not support use of type references.- 指定者:
getTypeLocator
在接口中EvaluationContext
- 返回:
TypeLocator
implementation that raises aSpelEvaluationException
withSpelMessage.TYPE_NOT_FOUND
.
getTypeConverter
public TypeConverter getTypeConverter()
The configuredTypeConverter
.By default this is
StandardTypeConverter
.
getTypeComparator
public TypeComparator getTypeComparator()
Return an instance ofStandardTypeComparator
.- 指定者:
getTypeComparator
在接口中EvaluationContext
getOperatorOverloader
public OperatorOverloader getOperatorOverloader()
Return an instance ofStandardOperatorOverloader
.- 指定者:
getOperatorOverloader
在接口中EvaluationContext
setVariable
public void setVariable(String name, Object value)
从接口复制的说明:EvaluationContext
Set a named variable within this evaluation context to a specified value.- 指定者:
setVariable
在接口中EvaluationContext
- 参数:
name
- variable to setvalue
- value to be placed in the variable
lookupVariable
public Object lookupVariable(String name)
从接口复制的说明:EvaluationContext
Look up a named variable within this evaluation context.- 指定者:
lookupVariable
在接口中EvaluationContext
- 参数:
name
- variable to lookup- 返回:
- the value of the variable, or
null
if not found
forPropertyAccessors
public static SimpleEvaluationContext.Builder forPropertyAccessors(PropertyAccessor... accessors)
Create aSimpleEvaluationContext
for the specifiedPropertyAccessor
delegates: typically a customPropertyAccessor
specific to a use case (e.g. attribute resolution in a custom data structure), potentially combined with aDataBindingPropertyAccessor
if property dereferences are needed as well.- 参数:
accessors
- the accessor delegates to use- 另请参阅:
DataBindingPropertyAccessor.forReadOnlyAccess()
,DataBindingPropertyAccessor.forReadWriteAccess()
forReadOnlyDataBinding
public static SimpleEvaluationContext.Builder forReadOnlyDataBinding()
Create aSimpleEvaluationContext
for read-only access to public properties viaDataBindingPropertyAccessor
.
forReadWriteDataBinding
public static SimpleEvaluationContext.Builder forReadWriteDataBinding()
Create aSimpleEvaluationContext
for read-write access to public properties viaDataBindingPropertyAccessor
.