类 SpelExpression
- java.lang.Object
- org.springframework.expression.spel.standard.SpelExpression
- 所有已实现的接口:
Expression
public class SpelExpression extends Object implements Expression
ASpelExpression
represents a parsed (valid) expression that is ready to be evaluated in a specified context. An expression can be evaluated standalone or in a specified context. During expression evaluation the context may be asked to resolve references to types, beans, properties, and methods.- 从以下版本开始:
- 3.0
- 作者:
- Andy Clement, Juergen Hoeller
构造器概要
构造器 构造器 说明 SpelExpression(String expression, SpelNodeImpl ast, SpelParserConfiguration configuration)
Construct an expression, only used by the parser.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 boolean
compileExpression()
Perform expression compilation.SpelNode
getAST()
Return the Abstract Syntax Tree for the expression.EvaluationContext
getEvaluationContext()
Return the default evaluation context that will be used if none is supplied on an evaluation call.String
getExpressionString()
Return the original string used to create this expression (unmodified).Object
getValue()
Evaluate this expression in the default standard context.<T> T
getValue(Class<T> expectedResultType)
Evaluate the expression in the default context.Object
getValue(Object rootObject)
Evaluate this expression against the specified root object.<T> T
getValue(Object rootObject, Class<T> expectedResultType)
Evaluate the expression in the default context against the specified root object.Object
getValue(EvaluationContext context)
Evaluate this expression in the provided context and return the result of evaluation.<T> T
getValue(EvaluationContext context, Class<T> expectedResultType)
Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc.Object
getValue(EvaluationContext context, Object rootObject)
Evaluate this expression in the provided context and return the result of evaluation, but use the supplied root context as an override for any default root object specified in the context.<T> T
getValue(EvaluationContext context, Object rootObject, Class<T> expectedResultType)
Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc.Class<?>
getValueType()
Return the most general type that can be passed to aExpression.setValue(java.lang.Object, java.lang.Object)
method using the default context.Class<?>
getValueType(Object rootObject)
Return the most general type that can be passed to theExpression.setValue(Object, Object)
method using the default context.Class<?>
getValueType(EvaluationContext context)
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object)
method for the given context.Class<?>
getValueType(EvaluationContext context, Object rootObject)
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object, Object)
method for the given context.TypeDescriptor
getValueTypeDescriptor()
Return the most general type that can be passed to aExpression.setValue(java.lang.Object, java.lang.Object)
method using the default context.TypeDescriptor
getValueTypeDescriptor(Object rootObject)
Return the most general type that can be passed to theExpression.setValue(Object, Object)
method using the default context.TypeDescriptor
getValueTypeDescriptor(EvaluationContext context)
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object)
method for the given context.TypeDescriptor
getValueTypeDescriptor(EvaluationContext context, Object rootObject)
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object, Object)
method for the given context.boolean
isWritable(Object rootObject)
Determine if an expression can be written to, i.e. setValue() can be called.boolean
isWritable(EvaluationContext context)
Determine if an expression can be written to, i.e. setValue() can be called.boolean
isWritable(EvaluationContext context, Object rootObject)
Determine if an expression can be written to, i.e. setValue() can be called.void
revertToInterpreted()
Cause an expression to revert to being interpreted if it has been using a compiled form.void
setEvaluationContext(EvaluationContext evaluationContext)
Set the evaluation context that will be used if none is specified on an evaluation call.void
setValue(Object rootObject, Object value)
Set this expression in the provided context to the value provided.void
setValue(EvaluationContext context, Object value)
Set this expression in the provided context to the value provided.void
setValue(EvaluationContext context, Object rootObject, Object value)
Set this expression in the provided context to the value provided.String
toStringAST()
Produce a string representation of the Abstract Syntax Tree for the expression.
构造器详细资料
SpelExpression
public SpelExpression(String expression, SpelNodeImpl ast, SpelParserConfiguration configuration)
Construct an expression, only used by the parser.
方法详细资料
setEvaluationContext
public void setEvaluationContext(EvaluationContext evaluationContext)
Set the evaluation context that will be used if none is specified on an evaluation call.- 参数:
evaluationContext
- the evaluation context to use
getEvaluationContext
public EvaluationContext getEvaluationContext()
Return the default evaluation context that will be used if none is supplied on an evaluation call.- 返回:
- the default evaluation context
getExpressionString
public String getExpressionString()
从接口复制的说明:Expression
Return the original string used to create this expression (unmodified).- 指定者:
getExpressionString
在接口中Expression
- 返回:
- the original expression string
getValue
public Object getValue() throws EvaluationException
从接口复制的说明:Expression
Evaluate this expression in the default standard context.- 指定者:
getValue
在接口中Expression
- 返回:
- the evaluation result
- 抛出:
EvaluationException
- if there is a problem during evaluation
getValue
public <T> T getValue(Class<T> expectedResultType) throws EvaluationException
从接口复制的说明:Expression
Evaluate the expression in the default context. If the result of the evaluation does not match (and cannot be converted to) the expected result type then an exception will be returned.- 指定者:
getValue
在接口中Expression
- 参数:
expectedResultType
- the class the caller would like the result to be- 返回:
- the evaluation result
- 抛出:
EvaluationException
- if there is a problem during evaluation
getValue
public Object getValue(Object rootObject) throws EvaluationException
从接口复制的说明:Expression
Evaluate this expression against the specified root object.- 指定者:
getValue
在接口中Expression
- 参数:
rootObject
- the root object against which to evaluate the expression- 返回:
- the evaluation result
- 抛出:
EvaluationException
- if there is a problem during evaluation
getValue
public <T> T getValue(Object rootObject, Class<T> expectedResultType) throws EvaluationException
从接口复制的说明:Expression
Evaluate the expression in the default context against the specified root object. If the result of the evaluation does not match (and cannot be converted to) the expected result type then an exception will be returned.- 指定者:
getValue
在接口中Expression
- 参数:
rootObject
- the root object against which to evaluate the expressionexpectedResultType
- the class the caller would like the result to be- 返回:
- the evaluation result
- 抛出:
EvaluationException
- if there is a problem during evaluation
getValue
public Object getValue(EvaluationContext context) throws EvaluationException
从接口复制的说明:Expression
Evaluate this expression in the provided context and return the result of evaluation.- 指定者:
getValue
在接口中Expression
- 参数:
context
- the context in which to evaluate the expression- 返回:
- the evaluation result
- 抛出:
EvaluationException
- if there is a problem during evaluation
getValue
public <T> T getValue(EvaluationContext context, Class<T> expectedResultType) throws EvaluationException
从接口复制的说明:Expression
Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc. The type of the evaluation result is expected to be of a particular class and an exception will be thrown if it is not and cannot be converted to that type.- 指定者:
getValue
在接口中Expression
- 参数:
context
- the context in which to evaluate the expressionexpectedResultType
- the class the caller would like the result to be- 返回:
- the evaluation result
- 抛出:
EvaluationException
- if there is a problem during evaluation
getValue
public Object getValue(EvaluationContext context, Object rootObject) throws EvaluationException
从接口复制的说明:Expression
Evaluate this expression in the provided context and return the result of evaluation, but use the supplied root context as an override for any default root object specified in the context.- 指定者:
getValue
在接口中Expression
- 参数:
context
- the context in which to evaluate the expressionrootObject
- the root object against which to evaluate the expression- 返回:
- the evaluation result
- 抛出:
EvaluationException
- if there is a problem during evaluation
getValue
public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> expectedResultType) throws EvaluationException
从接口复制的说明:Expression
Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc. The type of the evaluation result is expected to be of a particular class and an exception will be thrown if it is not and cannot be converted to that type. The supplied root object overrides any default specified on the supplied context.- 指定者:
getValue
在接口中Expression
- 参数:
context
- the context in which to evaluate the expressionrootObject
- the root object against which to evaluate the expressionexpectedResultType
- the class the caller would like the result to be- 返回:
- the evaluation result
- 抛出:
EvaluationException
- if there is a problem during evaluation
getValueType
public Class<?> getValueType() throws EvaluationException
从接口复制的说明:Expression
Return the most general type that can be passed to aExpression.setValue(java.lang.Object, java.lang.Object)
method using the default context.- 指定者:
getValueType
在接口中Expression
- 返回:
- the most general type of value that can be set on this context
- 抛出:
EvaluationException
- if there is a problem determining the type
getValueType
public Class<?> getValueType(Object rootObject) throws EvaluationException
从接口复制的说明:Expression
Return the most general type that can be passed to theExpression.setValue(Object, Object)
method using the default context.- 指定者:
getValueType
在接口中Expression
- 参数:
rootObject
- the root object against which to evaluate the expression- 返回:
- the most general type of value that can be set on this context
- 抛出:
EvaluationException
- if there is a problem determining the type
getValueType
public Class<?> getValueType(EvaluationContext context) throws EvaluationException
从接口复制的说明:Expression
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object)
method for the given context.- 指定者:
getValueType
在接口中Expression
- 参数:
context
- the context in which to evaluate the expression- 返回:
- the most general type of value that can be set on this context
- 抛出:
EvaluationException
- if there is a problem determining the type
getValueType
public Class<?> getValueType(EvaluationContext context, Object rootObject) throws EvaluationException
从接口复制的说明:Expression
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object, Object)
method for the given context. The supplied root object overrides any specified in the context.- 指定者:
getValueType
在接口中Expression
- 参数:
context
- the context in which to evaluate the expressionrootObject
- the root object against which to evaluate the expression- 返回:
- the most general type of value that can be set on this context
- 抛出:
EvaluationException
- if there is a problem determining the type
getValueTypeDescriptor
public TypeDescriptor getValueTypeDescriptor() throws EvaluationException
从接口复制的说明:Expression
Return the most general type that can be passed to aExpression.setValue(java.lang.Object, java.lang.Object)
method using the default context.- 指定者:
getValueTypeDescriptor
在接口中Expression
- 返回:
- a type descriptor for values that can be set on this context
- 抛出:
EvaluationException
- if there is a problem determining the type
getValueTypeDescriptor
public TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException
从接口复制的说明:Expression
Return the most general type that can be passed to theExpression.setValue(Object, Object)
method using the default context.- 指定者:
getValueTypeDescriptor
在接口中Expression
- 参数:
rootObject
- the root object against which to evaluate the expression- 返回:
- a type descriptor for values that can be set on this context
- 抛出:
EvaluationException
- if there is a problem determining the type
getValueTypeDescriptor
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context) throws EvaluationException
从接口复制的说明:Expression
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object)
method for the given context.- 指定者:
getValueTypeDescriptor
在接口中Expression
- 参数:
context
- the context in which to evaluate the expression- 返回:
- a type descriptor for values that can be set on this context
- 抛出:
EvaluationException
- if there is a problem determining the type
getValueTypeDescriptor
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject) throws EvaluationException
从接口复制的说明:Expression
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object, Object)
method for the given context. The supplied root object overrides any specified in the context.- 指定者:
getValueTypeDescriptor
在接口中Expression
- 参数:
context
- the context in which to evaluate the expressionrootObject
- the root object against which to evaluate the expression- 返回:
- a type descriptor for values that can be set on this context
- 抛出:
EvaluationException
- if there is a problem determining the type
isWritable
public boolean isWritable(Object rootObject) throws EvaluationException
从接口复制的说明:Expression
Determine if an expression can be written to, i.e. setValue() can be called.- 指定者:
isWritable
在接口中Expression
- 参数:
rootObject
- the root object against which to evaluate the expression- 返回:
true
if the expression is writable;false
otherwise- 抛出:
EvaluationException
- if there is a problem determining if it is writable
isWritable
public boolean isWritable(EvaluationContext context) throws EvaluationException
从接口复制的说明:Expression
Determine if an expression can be written to, i.e. setValue() can be called.- 指定者:
isWritable
在接口中Expression
- 参数:
context
- the context in which the expression should be checked- 返回:
true
if the expression is writable;false
otherwise- 抛出:
EvaluationException
- if there is a problem determining if it is writable
isWritable
public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException
从接口复制的说明:Expression
Determine if an expression can be written to, i.e. setValue() can be called. The supplied root object overrides any specified in the context.- 指定者:
isWritable
在接口中Expression
- 参数:
context
- the context in which the expression should be checkedrootObject
- the root object against which to evaluate the expression- 返回:
true
if the expression is writable;false
otherwise- 抛出:
EvaluationException
- if there is a problem determining if it is writable
setValue
public void setValue(Object rootObject, Object value) throws EvaluationException
从接口复制的说明:Expression
Set this expression in the provided context to the value provided.- 指定者:
setValue
在接口中Expression
- 参数:
rootObject
- the root object against which to evaluate the expressionvalue
- the new value- 抛出:
EvaluationException
- if there is a problem during evaluation
setValue
public void setValue(EvaluationContext context, Object value) throws EvaluationException
从接口复制的说明:Expression
Set this expression in the provided context to the value provided.- 指定者:
setValue
在接口中Expression
- 参数:
context
- the context in which to set the value of the expressionvalue
- the new value- 抛出:
EvaluationException
- if there is a problem during evaluation
setValue
public void setValue(EvaluationContext context, Object rootObject, Object value) throws EvaluationException
从接口复制的说明:Expression
Set this expression in the provided context to the value provided. The supplied root object overrides any specified in the context.- 指定者:
setValue
在接口中Expression
- 参数:
context
- the context in which to set the value of the expressionrootObject
- the root object against which to evaluate the expressionvalue
- the new value- 抛出:
EvaluationException
- if there is a problem during evaluation
compileExpression
public boolean compileExpression()
Perform expression compilation. This will only succeed once exit descriptors for all nodes have been determined. If the compilation fails and has failed more than 100 times the expression is no longer considered suitable for compilation.- 返回:
- whether this expression has been successfully compiled
revertToInterpreted
public void revertToInterpreted()
Cause an expression to revert to being interpreted if it has been using a compiled form. It also resets the compilation attempt failure count (an expression is normally no longer considered compilable if it cannot be compiled after 100 attempts).
toStringAST
public String toStringAST()
Produce a string representation of the Abstract Syntax Tree for the expression. This should ideally look like the input expression, but properly formatted since any unnecessary whitespace will have been discarded during the parse of the expression.- 返回:
- the string representation of the AST