In this post under Java, I will show with example how to sort an array. Below is the complete main method for reference. Main class package core.collection; import java.util.Arrays; public class ArraysSortDemo { public static void main(String[] args) { int[] integerList = new int[] {5, 2, 3, 1, 4}; Arrays.sort(integerList); for(int value : integerList) {…… Continue reading Sorting Array
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
Mapping using direct field access
In all my previous post under MapStruct, in the examples I showed MapStruct used to call public getter and setter methods to map data from one object to another. It is not compulsory that we should always have public getter and setter methods. MapStruct can directly access the fields if they are marked “public” or…… Continue reading Mapping using direct field access
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
Projecting maps in SpEL
In this post under SpEL, I will show with example how to project a specific field (key or value field) of a map. Below is the complete main code showing how to do it. Main class 1 package spel.package14; 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.ComponentScan;…… Continue reading Projecting maps in SpEL
Projecting collections in SpEL
In this post under Spring SpEL, I will show with example how to project certain fields of a collection of objects instead of whole object itself. For our example, we use the below class structure Employee package spel.package13; public class Employee { private int id; private String name; private int salary; public Employee(int id, String…… Continue reading Projecting collections in SpEL
Filtering maps in SpEL
In this post I will explain with example how to filter maps in SpEL expression. For our example we will use the below main class Main class package spel.package12; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import java.util.HashMap; import java.util.Map; @Configuration @ComponentScan(basePackages = “spel.package12”) public class Example12 { @Value(“#{maps.?[key >=…… Continue reading Filtering maps in SpEL
Filtering collections in SpEL
In this post, I will explain with example how to filter collections in SpEL. For our example we will use the below model class Student package spel.package11; public class Employee { private int id; private String name; private int salary; public Employee(int id, String name, int salary) { this.id = id; this.name = name; this.salary…… Continue reading Filtering collections in SpEL