Organize and clean up SpEL documentation tests
This commit is contained in:
parent
a82108ec73
commit
17ee82e004
|
@ -40,11 +40,7 @@ Java::
|
||||||
public abstract class StringUtils {
|
public abstract class StringUtils {
|
||||||
|
|
||||||
public static String reverseString(String input) {
|
public static String reverseString(String input) {
|
||||||
StringBuilder backwards = new StringBuilder(input.length());
|
return new StringBuilder(input).reverse().toString();
|
||||||
for (int i = 0; i < input.length(); i++) {
|
|
||||||
backwards.append(input.charAt(input.length() - 1 - i));
|
|
||||||
}
|
|
||||||
return backwards.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
@ -54,11 +50,7 @@ Kotlin::
|
||||||
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
|
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
|
||||||
----
|
----
|
||||||
fun reverseString(input: String): String {
|
fun reverseString(input: String): String {
|
||||||
val backwards = StringBuilder(input.length)
|
return StringBuilder(input).reverse().toString()
|
||||||
for (i in 0 until input.length) {
|
|
||||||
backwards.append(input[input.length - 1 - i])
|
|
||||||
}
|
|
||||||
return backwards.toString()
|
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
======
|
======
|
||||||
|
@ -161,9 +153,9 @@ Java::
|
||||||
.bindTo(varargs); //here we have to provide arguments in a single array binding
|
.bindTo(varargs); //here we have to provide arguments in a single array binding
|
||||||
context.setVariable("message", mh);
|
context.setVariable("message", mh);
|
||||||
|
|
||||||
|
// evaluates to "This is a prerecorded message with 3 words: <Oh Hello World!>"
|
||||||
String message = parser.parseExpression("#message()")
|
String message = parser.parseExpression("#message()")
|
||||||
.getValue(context, String.class);
|
.getValue(context, String.class);
|
||||||
//returns "This is a prerecorded message with 3 words: <Oh Hello World!>"
|
|
||||||
----
|
----
|
||||||
|
|
||||||
Kotlin::
|
Kotlin::
|
||||||
|
@ -182,6 +174,7 @@ Kotlin::
|
||||||
.bindTo(varargs) //here we have to provide arguments in a single array binding
|
.bindTo(varargs) //here we have to provide arguments in a single array binding
|
||||||
context.setVariable("message", mh)
|
context.setVariable("message", mh)
|
||||||
|
|
||||||
|
// evaluates to "This is a prerecorded message with 3 words: <Oh Hello World!>"
|
||||||
val message = parser.parseExpression("#message()")
|
val message = parser.parseExpression("#message()")
|
||||||
.getValue(context, String::class.java)
|
.getValue(context, String::class.java)
|
||||||
----
|
----
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[[expressions-templating]]
|
[[expressions-templating]]
|
||||||
= Expression templating
|
= Expression Templating
|
||||||
|
|
||||||
Expression templates allow mixing literal text with one or more evaluation blocks.
|
Expression templates allow mixing literal text with one or more evaluation blocks.
|
||||||
Each evaluation block is delimited with prefix and suffix characters that you can
|
Each evaluation block is delimited with prefix and suffix characters that you can
|
||||||
|
@ -32,53 +32,13 @@ Kotlin::
|
||||||
======
|
======
|
||||||
|
|
||||||
The string is evaluated by concatenating the literal text `'random number is '` with the
|
The string is evaluated by concatenating the literal text `'random number is '` with the
|
||||||
result of evaluating the expression inside the `#{ }` delimiter (in this case, the result
|
result of evaluating the expression inside the `#{ }` delimiters (in this case, the
|
||||||
of calling that `random()` method). The second argument to the `parseExpression()` method
|
result of calling that `random()` method). The second argument to the `parseExpression()`
|
||||||
is of the type `ParserContext`. The `ParserContext` interface is used to influence how
|
method is of the type `ParserContext`. The `ParserContext` interface is used to influence
|
||||||
the expression is parsed in order to support the expression templating functionality.
|
how the expression is parsed in order to support the expression templating functionality.
|
||||||
The definition of `TemplateParserContext` follows:
|
The `TemplateParserContext` used in the previous example resides in the
|
||||||
|
`org.springframework.expression.common` package and is an implementation of the
|
||||||
[tabs]
|
`ParserContext` which by default configures the prefix and suffix to `#{` and `}`,
|
||||||
======
|
respectively.
|
||||||
Java::
|
|
||||||
+
|
|
||||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
|
||||||
----
|
|
||||||
public class TemplateParserContext implements ParserContext {
|
|
||||||
|
|
||||||
public String getExpressionPrefix() {
|
|
||||||
return "#{";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getExpressionSuffix() {
|
|
||||||
return "}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTemplate() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
----
|
|
||||||
|
|
||||||
Kotlin::
|
|
||||||
+
|
|
||||||
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
|
|
||||||
----
|
|
||||||
class TemplateParserContext : ParserContext {
|
|
||||||
|
|
||||||
override fun getExpressionPrefix(): String {
|
|
||||||
return "#{"
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getExpressionSuffix(): String {
|
|
||||||
return "}"
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isTemplate(): Boolean {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
----
|
|
||||||
======
|
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue