Spring Expression Language

When using the ${} syntax, you are in fact using Spring Expression Language (SpEL). There are several variants of EL available in the wild; SpEl is one of the most powerful variants.

Here is an overview of its main features:

Feature

Syntax

Explanation

Accessing a list element

list[0]

 

Accessing a map entry

map[key]

 

Ternary operator

condition ? 'yes' : 'no'

 

Elvis operator

person ?: default

Returns default if person's value is null

Safe navigation

person?.name

Returns null if person or her name is null

Templating

'Your name is #{person.name}'

Injects values into a string

Projections

${persons.![name]}

Extracts the names of all the persons and puts them into a list

Selection

persons.?[name ...

Get Spring MVC: Designing Real-World Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.