You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/main/antora/modules/ROOT/pages/value-expressions.adoc
+34-3
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,22 @@
1
1
[[valueexpressions.fundamentals]]
2
2
= Value Expressions Fundamentals
3
3
4
-
Value Expressions are a combination of {spring-framework-docs}/core/expressions.html[Spring Expression Language (SpEL)] and {spring-framework-docs}/core/beans/environment.html#beans-placeholder-resolution-in-statements[Property Placeholder Resolution].
4
+
Value Expressions are a combination of {spring-framework-docs}/core/expressions.html[Spring Expression Language (SpEL)] and {spring-framework-docs}/core/beans/annotation-config/value-annotations.html[Property Placeholder Resolution].
5
5
They combine powerful evaluation of programmatic expressions with the simplicity to resort to property-placeholder resolution to obtain values from the `Environment` such as configuration properties.
6
6
7
7
Expressions are expected to be defined by a trusted input such as an annotation value and not to be determined from user input.
8
8
9
-
The following code demonstrates how to use expressions in the context of annotations.
9
+
== Scope
10
10
11
-
.Annotation Usage
11
+
Value Expressions are used in contexts across annotations.
12
+
Spring Data offers Value Expression evaluation in two main contexts:
13
+
14
+
* *Mapping Model Annotations*: such as `@Document`, `@Field`, `@Value` and other annotations in Spring Data modules that ship with their own mapping models respective Entity Readers such as MongoDB, Elasticsearch, Cassandra, Neo4j.
15
+
Modules that build on libraries providing their own mapping models (JPA, LDAP) do not support Value Expressions in mapping annotations.
16
+
+
17
+
The following code demonstrates how to use expressions in the context of mapping model annotations.
18
+
+
19
+
.`@Document` Annotation Usage
12
20
====
13
21
[source,java]
14
22
----
@@ -19,6 +27,27 @@ class Order {
19
27
----
20
28
====
21
29
30
+
* *Repository Query Methods*: primarily through `@Query`.
31
+
+
32
+
The following code demonstrates how to use expressions in the context of repository query methods.
33
+
+
34
+
.`@Query` Annotation Usage
35
+
====
36
+
[source,java]
37
+
----
38
+
class OrderRepository extends Repository<Order, String> {
39
+
40
+
@Query("select u from User u where u.tenant = ?${spring.application.name:unknown} and u.firstname like %?#{escape([0])}% escape ?#{escapeCharacter()}")
NOTE: Consult your module's documentation to determine the actual parameter by-name/by-index binding syntax.
47
+
Typically, expressions are prefixed with `:#{…}`/`:${…}` or `?#{…}`/`?${…}`.
48
+
49
+
== Expression Syntax
50
+
22
51
Value Expressions can be defined from a sole SpEL Expression, a Property Placeholder or a composite expression mixing various expressions including literals.
NOTE: Using value expressions introduces a lot of flexibility to your code.
43
72
Doing so requires evaluation of the expression on each usage and, therefore, value expression evaluation has an impact on the performance profile.
44
73
74
+
{spring-framework-docs}/core/expressions/language-ref.html[Spring Expression Language (SpEL)] and {spring-framework-docs}/core/beans/annotation-config/value-annotations.html[Property Placeholder Resolution] explain the syntax and capabilities of SpEL and Property Placeholders in detail.
0 commit comments