提交 01e50fb6 编写于 作者: S Sam Brannen

Polish SpEL chapter

上级 6c3a0a90
......@@ -517,7 +517,7 @@ kinds of expression cannot be compiled at the moment:
* Expressions using custom resolvers or accessors
* Expressions using selection or projection
More types of expression will be compilable in the future.
More types of expressions will be compilable in the future.
......@@ -589,7 +589,7 @@ You can also refer to other bean properties by name, as the following example sh
To specify a default value, you can place the `@Value` annotation on fields, methods,
and method or constructor parameters.
The following example sets the default value of a field variable:
The following example sets the default value of a field:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
......@@ -788,7 +788,7 @@ using a literal on one side of a logical comparison operator.
----
Numbers support the use of the negative sign, exponential notation, and decimal points.
By default, real numbers are parsed by using Double.parseDouble().
By default, real numbers are parsed by using `Double.parseDouble()`.
......@@ -796,10 +796,10 @@ By default, real numbers are parsed by using Double.parseDouble().
=== Properties, Arrays, Lists, Maps, and Indexers
Navigating with property references is easy. To do so, use a period to indicate a nested
property value. The instances of the `Inventor` class, `pupin` and `tesla`, were populated with
data listed in the <<expressions-example-classes, Classes used in the examples>> section.
To navigate "`down`" and get Tesla's year of birth and Pupin's city of birth, we use the following
expressions:
property value. The instances of the `Inventor` class, `pupin` and `tesla`, were
populated with data listed in the <<expressions-example-classes, Classes used in the
examples>> section. To navigate "down" the object graph and get Tesla's year of birth and
Pupin's city of birth, we use the following expressions:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
......@@ -939,7 +939,7 @@ You can directly express lists in an expression by using `{}` notation.
----
`{}` by itself means an empty list. For performance reasons, if the list is itself
entirely composed of fixed literals, a constant list is created to represent the
entirely composed of fixed literals, a constant list is created to represent the
expression (rather than building a new list on each evaluation).
......@@ -967,10 +967,11 @@ following example shows how to do so:
val mapOfMaps = parser.parseExpression("{name:{first:'Nikola',last:'Tesla'},dob:{day:10,month:'July',year:1856}}").getValue(context) as Map<*, *>
----
`{:}` by itself means an empty map. For performance reasons, if the map is itself composed
of fixed literals or other nested constant structures (lists or maps), a constant map is created
to represent the expression (rather than building a new map on each evaluation). Quoting of the map keys
is optional. The examples above do not use quoted keys.
`{:}` by itself means an empty map. For performance reasons, if the map is itself
composed of fixed literals or other nested constant structures (lists or maps), a
constant map is created to represent the expression (rather than building a new map on
each evaluation). Quoting of the map keys is optional (unless the key contains a period
(`.`)). The examples above do not use quoted keys.
......@@ -1003,8 +1004,7 @@ to have the array populated at construction time. The following example shows ho
val numbers3 = parser.parseExpression("new int[4][5]").getValue(context) as Array<IntArray>
----
You cannot currently supply an initializer when you construct
multi-dimensional array.
You cannot currently supply an initializer when you construct a multi-dimensional array.
......@@ -1105,7 +1105,7 @@ expression-based `matches` operator. The following listing shows examples of bot
boolean trueValue = parser.parseExpression(
"'5.00' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
//evaluates to false
// evaluates to false
boolean falseValue = parser.parseExpression(
"'5.0067' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
----
......@@ -1120,14 +1120,14 @@ expression-based `matches` operator. The following listing shows examples of bot
val trueValue = parser.parseExpression(
"'5.00' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean::class.java)
//evaluates to false
// evaluates to false
val falseValue = parser.parseExpression(
"'5.0067' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean::class.java)
----
CAUTION: Be careful with primitive types, as they are immediately boxed up to the wrapper type,
so `1 instanceof T(int)` evaluates to `false` while `1 instanceof T(Integer)`
evaluates to `true`, as expected.
CAUTION: Be careful with primitive types, as they are immediately boxed up to their
wrapper types. For example, `1 instanceof T(int)` evaluates to `false`, while
`1 instanceof T(Integer)` evaluates to `true`, as expected.
Each symbolic operator can also be specified as a purely alphabetic equivalent. This
avoids problems where the symbols used have special meaning for the document type in
......@@ -1155,7 +1155,7 @@ SpEL supports the following logical operators:
* `or` (`||`)
* `not` (`!`)
The following example shows how to use the logical operators
The following example shows how to use the logical operators:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
......@@ -1222,10 +1222,11 @@ The following example shows how to use the logical operators
[[expressions-operators-mathematical]]
==== Mathematical Operators
You can use the addition operator on both numbers and strings. You can use the subtraction, multiplication,
and division operators only on numbers. You can also use
the modulus (%) and exponential power (^) operators. Standard operator precedence is enforced. The
following example shows the mathematical operators in use:
You can use the addition operator (`+`) on both numbers and strings. You can use the
subtraction (`-`), multiplication (`*`), and division (`/`) operators only on numbers.
You can also use the modulus (`%`) and exponential power (`^`) operators on numbers.
Standard operator precedence is enforced. The following example shows the mathematical
operators in use:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
......@@ -1296,9 +1297,9 @@ following example shows the mathematical operators in use:
[[expressions-assignment]]
==== The Assignment Operator
To setting a property, use the assignment operator (`=`). This is typically
done within a call to `setValue` but can also be done inside a call to `getValue`. The
following listing shows both ways to use the assignment operator:
To set a property, use the assignment operator (`=`). This is typically done within a
call to `setValue` but can also be done inside a call to `getValue`. The following
listing shows both ways to use the assignment operator:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
......@@ -1333,9 +1334,9 @@ You can use the special `T` operator to specify an instance of `java.lang.Class`
type). Static methods are invoked by using this operator as well. The
`StandardEvaluationContext` uses a `TypeLocator` to find types, and the
`StandardTypeLocator` (which can be replaced) is built with an understanding of the
`java.lang` package. This means that `T()` references to types within `java.lang` do not need to be
fully qualified, but all other type references must be. The following example shows how
to use the `T` operator:
`java.lang` package. This means that `T()` references to types within the `java.lang`
package do not need to be fully qualified, but all other type references must be. The
following example shows how to use the `T` operator:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
......@@ -1365,9 +1366,10 @@ to use the `T` operator:
[[expressions-constructors]]
=== Constructors
You can invoke constructors by using the `new` operator. You should use the fully qualified class name
for all but the types located in the core package `java.lang`. The following
example shows how to use the `new` operator to invoke constructors:
You can invoke constructors by using the `new` operator. You should use the fully
qualified class name for all types except those located in the `java.lang` package
(`Integer`, `Float`, `String`, and so on). The following example shows how to use the
`new` operator to invoke constructors:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
......@@ -1376,7 +1378,7 @@ example shows how to use the `new` operator to invoke constructors:
"new org.spring.samples.spel.inventor.Inventor('Albert Einstein', 'German')")
.getValue(Inventor.class);
//create new inventor instance within add method of List
// create new Inventor instance within the add() method of List
p.parseExpression(
"Members.add(new org.spring.samples.spel.inventor.Inventor(
'Albert Einstein', 'German'))").getValue(societyContext);
......@@ -1388,7 +1390,7 @@ example shows how to use the `new` operator to invoke constructors:
"new org.spring.samples.spel.inventor.Inventor('Albert Einstein', 'German')")
.getValue(Inventor::class.java)
//create new inventor instance within add method of List
// create new Inventor instance within the add() method of List
p.parseExpression(
"Members.add(new org.spring.samples.spel.inventor.Inventor('Albert Einstein', 'German'))")
.getValue(societyContext)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册