Skip to content

Commit 00409b3

Browse files
committed
Refine Value Expression documentation.
Closes #3214
1 parent 4718c45 commit 00409b3

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/main/antora/modules/ROOT/pages/value-expressions.adoc

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
[[valueexpressions.fundamentals]]
22
= Value Expressions Fundamentals
33

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].
55
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.
66

77
Expressions are expected to be defined by a trusted input such as an annotation value and not to be determined from user input.
88

9-
The following code demonstrates how to use expressions in the context of annotations.
9+
== Scope
1010

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
1220
====
1321
[source,java]
1422
----
@@ -19,6 +27,27 @@ class Order {
1927
----
2028
====
2129

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()}")
41+
List<Order> findContainingEscaped(String namePart);
42+
}
43+
----
44+
====
45+
46+
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+
2251
Value Expressions can be defined from a sole SpEL Expression, a Property Placeholder or a composite expression mixing various expressions including literals.
2352

2453
.Expression Examples
@@ -42,6 +71,8 @@ orders-${tenant-config.suffix} <4>
4271
NOTE: Using value expressions introduces a lot of flexibility to your code.
4372
Doing so requires evaluation of the expression on each usage and, therefore, value expression evaluation has an impact on the performance profile.
4473

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.
75+
4576
[[valueexpressions.api]]
4677
== Parsing and Evaluation
4778

0 commit comments

Comments
 (0)