In this post under Spring SpEl, I will explain with example the purpose of Elvis operator. Lets say you have below statement written using ternary operator String result = (data != null) ? data : null; In the above statement “data” variable is of type String. So we are checking if “data” is not null,…… Continue reading Elvis operator
Category: SpEL
Safe navigation operator
In this post under Spring SpEl, I will explain with example the usage of safe navigation operator. Lets say we have below pojo class Employee package spel.package24; public class Employee { private Integer id; private String name; private int salary; public Employee() { } public Employee(Integer id, String name, int salary) { this.id = id;…… Continue reading Safe navigation operator
autoGrowCollections example
In this post under Spring SpEL, I will show with example the purpose of “autoGrowCollections” configuration. When evaluating a SpEL expression, containing collections, if we try to access an entry which doesn’t exist in collection. We get an exception. Lets say we have the below pojo class Employee package spel.package22; public class Employee { private…… Continue reading autoGrowCollections example
autoGrowNullReferences example
In this post under Spring SpEL, I will show with example the purpose of “autoGrowNullReferences” configuration. When evaluating a SpEL expression, containing chain of property references, if one of the property in the chain is null we get an exception. To prevent that we use the “autoGrowNullReferences” configuration. It’s data type is boolean. By default…… Continue reading autoGrowNullReferences example
Making Java objects available during sqel expression evaluation
In this post under Spring SpEL, I will explain with example how to make java objects available to SpElExpression during its evaluation. For our example we will use the below pojo class Employee package spel.package20; public class Employee { private int id; private String name; private int salary; public Employee(int id, String name, int salary)…… Continue reading Making Java objects available during sqel expression evaluation
SpelExpressionParser example
In all my previous post under Spring SpEL, I was letting Spring framework to evaluate the SpEL expression when creating the Spring application context. In addition to that we can manually evaluate a SpEL expression using SpelExpressionParser class. This class is provided by Spring framework and below example shows how to use it. Main class…… Continue reading SpelExpressionParser example
Ternary operator in SpEL
In this post under Spring SpEL, I will show with example how to use ternary operator in SpEL. Below is the main class for your reference. Main class 1 package spel.package18; 2 3 import org.springframework.beans.factory.annotation.Value; 4 import org.springframework.context.ApplicationContext; 5 import org.springframework.context.annotation.AnnotationConfigApplicationContext; 6 import org.springframework.context.annotation.Bean; 7 import org.springframework.context.annotation.Configuration; 8 9 import java.util.Arrays; 10 import java.util.List; 11…… Continue reading Ternary operator in SpEL
Expression Templating Example
In this post under Spring SpEL, I will explain with example what is “Expression Templating”. Expression Templating is a way by which we can mix literal text with one or more SpEL expressions and create a String template. At runtime the expressions in the template are replaced by actual value. Each expression in the String…… Continue reading Expression Templating Example
Projecting and Filtering collections in SpEL
In the previous post under Spring SpEL, I showed how to apply filtering and then projection on a collection in SpEL. In this post I will show with example how to apply projection and then filtering on a collection in SpEL. For our example I will use the below Pojo class Employee class package spel.package16;…… Continue reading Projecting and Filtering collections in SpEL
Filtering and Projecting collections in SpEL
In my previous two posts under Spring SpEL, I explained how to do filtering and projections using SpEL but separately. In this post I will show an example in which I will combine both filtering and projections technique in one SpEL. I will first do filtering on the collection and then on the result of…… Continue reading Filtering and Projecting collections in SpEL