@@ -744,25 +744,42 @@ topics:
744
744
[[expressions-ref-literal]]
745
745
=== Literal Expressions
746
746
747
- The types of literal expressions supported are strings, numeric values (int, real, hex),
748
- boolean, and null. Strings are delimited by single quotation marks. To put a single quotation mark itself
749
- in a string, use two single quotation mark characters.
747
+ SpEL supports the following types of literal expressions.
750
748
751
- The following listing shows simple usage of literals. Typically, they are not used
752
- in isolation like this but, rather, as part of a more complex expression -- for example,
753
- using a literal on one side of a logical comparison operator.
749
+ - strings
750
+ - numeric values: integer (`int` or `long`), hexadecimal (`int` or `long`), real (`float`
751
+ or `double`)
752
+ - boolean values: `true` or `false`
753
+ - null
754
+
755
+ Strings can delimited by single quotation marks (`'`) or double quotation marks (`"`). To
756
+ include a single quotation mark within a string literal enclosed in single quotation
757
+ marks, use two adjacent single quotation mark characters. Similarly, to include a double
758
+ quotation mark within a string literal enclosed in double quotation marks, use two
759
+ adjacent double quotation mark characters.
760
+
761
+ Numbers support the use of the negative sign, exponential notation, and decimal points.
762
+ By default, real numbers are parsed by using `Double.parseDouble()`.
763
+
764
+ The following listing shows simple usage of literals. Typically, they are not used in
765
+ isolation like this but, rather, as part of a more complex expression -- for example,
766
+ using a literal on one side of a logical comparison operator or as an argument to a
767
+ method.
754
768
755
769
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
756
770
.Java
757
771
----
758
772
ExpressionParser parser = new SpelExpressionParser();
759
773
760
- // evals to "Hello World"
774
+ // evaluates to "Hello World"
761
775
String helloWorld = (String) parser.parseExpression("'Hello World'").getValue();
762
776
777
+ // evaluates to "Tony's Pizza"
778
+ String pizzaParlor = (String) parser.parseExpression("'Tony''s Pizza'").getValue();
779
+
763
780
double avogadrosNumber = (Double) parser.parseExpression("6.0221415E+23").getValue();
764
781
765
- // evals to 2147483647
782
+ // evaluates to 2147483647
766
783
int maxValue = (Integer) parser.parseExpression("0x7FFFFFFF").getValue();
767
784
768
785
boolean trueValue = (Boolean) parser.parseExpression("true").getValue();
@@ -774,22 +791,22 @@ using a literal on one side of a logical comparison operator.
774
791
----
775
792
val parser = SpelExpressionParser()
776
793
777
- // evals to "Hello World"
794
+ // evaluates to "Hello World"
778
795
val helloWorld = parser.parseExpression("'Hello World'").value as String
779
796
797
+ // evaluates to "Tony's Pizza"
798
+ val pizzaParlor = parser.parseExpression("'Tony''s Pizza'").value as String
799
+
780
800
val avogadrosNumber = parser.parseExpression("6.0221415E+23").value as Double
781
801
782
- // evals to 2147483647
802
+ // evaluates to 2147483647
783
803
val maxValue = parser.parseExpression("0x7FFFFFFF").value as Int
784
804
785
805
val trueValue = parser.parseExpression("true").value as Boolean
786
806
787
807
val nullValue = parser.parseExpression("null").value
788
808
----
789
809
790
- Numbers support the use of the negative sign, exponential notation, and decimal points.
791
- By default, real numbers are parsed by using `Double.parseDouble()`.
792
-
793
810
794
811
795
812
[[expressions-properties-arrays]]
@@ -804,15 +821,15 @@ Pupin's city of birth, we use the following expressions:
804
821
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
805
822
.Java
806
823
----
807
- // evals to 1856
824
+ // evaluates to 1856
808
825
int year = (Integer) parser.parseExpression("birthdate.year + 1900").getValue(context);
809
826
810
827
String city = (String) parser.parseExpression("placeOfBirth.city").getValue(context);
811
828
----
812
829
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
813
830
.Kotlin
814
831
----
815
- // evals to 1856
832
+ // evaluates to 1856
816
833
val year = parser.parseExpression("birthdate.year + 1900").getValue(context) as Int
817
834
818
835
val city = parser.parseExpression("placeOfBirth.city").getValue(context) as String
0 commit comments