SPR-7674 - Documented value defaulting in Spring EL

Added short note of how to use the Elvis operator for defaulting values in the Spring expression language sections.
This commit is contained in:
Oliver Gierke 2010-12-28 09:42:58 +00:00
parent bfb3003cba
commit f20ded5f63
1 changed files with 9 additions and 0 deletions

View File

@ -1011,6 +1011,15 @@ tesla.setPlaceOfBirth(null);
city = parser.parseExpression("PlaceOfBirth?.City").getValue(context, String.class);
System.out.println(city); // null - does not throw NullPointerException!!!</programlisting>
<note>
<para>The Elvis operator can be used to apply default values in
expressions, e.g. in an <interfacename>@Value</interfacename> expression:</para>
<programlisting>@Value("#{systemProperties['pop3.port'] ?: 25}")</programlisting>
<para>This will inject a system property <code>pop3.port</code> if it
is defined or 25 if not.</para>
</note>
</section>
<section>