Spring Tutorials

Spring Tutorial

Introduction of Spring Framework

Advantages and Disadvantages of Spring Framework

Features of Spring Framework

Basic concept of Spring Framework

Architecture of Spring Framework

Modules of Spring Framework

Goal of Spring Framework

Create Application of Spring without any IDE

Create Application of Spring in Eclipse IDE

Create Application of Spring in MYEclipse IDE

Important JAR of Spring Framework

IOC container in Spring Framework

Bean and Applicationcontext container in Spring Framework

Example of Spring BeanFactory Container in Spring Framework

Example of Spring ApplicationContext Container in Spring Framework

Bean in Spring Framework

Lifecycle of Bean in Spring Framework

Scope of Bean in Spring Framework

Autowiring in Spring Framework

Dependency Injection in Spring Framework

Constructor-based Dependency Injection Example in Spring Framework

Setter-based Dependency Injection Example in Spring Framework

Introduction of AOP in Spring Framework

Core concept and Goal of AOP in Spring Framework

AOP Proxies in Spring framework

XML Schema Based AOP in Spring Framework

AOP Xml based Configuration Example in Spring Framework

Example of Declaring AOP Advices in Spring Framework

AOP AspectJ Annotation with Example in Spring Framework

Declaring an aspect and pointcut using Annotation in Spring Framework

Declaring AOP Advices using Annotation Example in Spring Framework

DAO support in Spring Framework

Introduction of Spring JDBC Framework in Spring Framework

Introduction of Spring JdbcTemplate in Spring Framework

Example of Spring JdbcTemplate class in Spring framework

Example of Executing SQL statements in Spring Framework

Example of Executing DDL statements in Spring Framework

SQL Stored Procedure in Spring Framework

Example of NamedParameterJdbcTemplate in Spring Framework

Example of RowMapperJdbcTemplate in Spring Framework

Introduction of ORM Framework in Spring Framework

Integration of Spring with Hibernate in Spring Framework

Integration of Spring with JPA in Spring Framework

Introduction of Spring Expression Language (SpEL) in Spring Framework

Example of Spring Expression Language (SpEL) in Spring framework

Example of Spring EL in XML and Annotation in Spring Framework

Language Reference with SpEL in Spring Framework

Operators in Spring Expression Language(SpEL) in Spring Framework

Variable in Spring Expression Language(SpEL) in Spring Framework

Introduction of Spring Framework Transaction Management in Spring Framework

Spring Framework Transaction Abstraction

Spring Declarative Transaction Management in Spring Framework

Spring Programmatic Transaction Management in Spring Framework

Introduction of Spring OXM (Object XML Mapping) in Spring Framework

Integration of Spring with Jaxb Example in Spring framework

Example of Spring with Xstream in Spring Framework

Example of Spring with Castor in Spring Framework

Remote Method Invocation(RMI) in Spring Framework

Spring and RMI Integration with Example in Spring Framework

Example of Spring and Httpinvoker in Spring Framework

Example of Spring and Hessian in Spring Framework

Integration of Spring with JMS in Spring Framework

Introduction of Webservice in Spring Framework

Spring Web Services in Spring Framework

Web Services with Jax-WS in Spring framework

Exposing and Exporting servlet-based Web Services using JAX-WS in Spring Framework

Accessing Web Services using JAX-WS in Spring Framework

Introduction of JMS in Spring Framework

JMS Messaging Models in Spring Framework

Using Spring JMS in Spring Framework

Sending and Receiving a Message Using JMS API in Spring Framework

Introduction of JMX (Java Management Extension) in Spring Framework

Integrating Beans with JMX in Spring Framework

Creating a MBeanServer in Spring Framework

Introduction Java Mail with Spring in Spring Framework

Example of Java Mail with spring in Spring Framework

Introduction of EJB(Enterprise JavaBeans) in Spring Framework

Introduction of EJB(Enterprise JavaBeans) Integration in Spring Framework

Integration of Spring With Struts 2 Example in Spring Framework

Spring MVC

Spring MVC

adplus-dvertising
Operators in Spring Expression Language(SpEL)
Previous Home Next

We can use many operators in SpEL such as arithmetic, relational, logical etc. There are given a lot of examples of using different operators in SpEL as given below.

Relational operators

The relational operators; equal, not equal, less than, less than or equal, greater than, and greater than or equal are supported using standard operator notation. the syntax used in SpEl as given below.

//evaluates to true
boolean trueValue = parser.parseExpression("3 == 3")
.getValue(Boolean.class);

//evaluates to false
boolean falseValue = parser.parseExpression("2 < -1.0")
.getValue(Boolean.class);

//evaluates to true
boolean trueValue = parser.parseExpression("'bay' < 'boy'")
.getValue(Boolean.class);
Logical operators

The logical operators that are supported are and, or, and not. the syntax used in SpEl as given below.

/-- AND --
//evaluates to false
boolean falseValue = parser.parseExpression("true and false")
.getValue(Boolean.class);

//evaluates to true
String expression = "isMember('John Smith') and isMember('Employee')";
boolean trueValue = parser.parseExpression(expression)
.getValue(societyContext, Boolean.class);

//-- OR --
//evaluates to true
boolean trueValue = parser.parseExpression("true or false")
.getValue(Boolean.class);

//evaluates to true
String expression = "isMember('John Smith') or isMember('Social Service')";
boolean trueValue = parser.parseExpression(expression)
.getValue(societyContext, Boolean.class);

//-- NOT --
//evaluates to false
boolean falseValue = parser.parseExpression("!true")
.getValue(Boolean.class);

//-- AND and NOT --
String expression = "isMember('John Smith') and !isMember('Employee')";
boolean falseValue = parser.parseExpression(expression)
.getValue(societyContext, Boolean.class);
Mathematical operators

The addition operator can be used on both numbers and strings. Subtraction, multiplication and division can be used only on numbers. Other mathematical operators supported are modulus (%) and exponential power (^).

//Addition
int num = parser.parseExpression("5 + 1")
.getValue(Integer.class); // 6

// hello spring
String testString = parser.parseExpression
("'hello' + ' ' + 'spring'").getValue(String.class); 

//Subtraction
int num = parser.parseExpression("2 - -3")
.getValue(Integer.class); // 5

double d = parser.parseExpression("1000.00 - 1e4")
.getValue(Double.class); // -9000

//Multiplication
int num = parser.parseExpression("-3 * -3")
.getValue(Integer.class); // 9

double num = parser.parseExpression("2.0 * 3e0 * 4")
.getValue(Double.class); // 24.0

//Division
int num = parser.parseExpression("6 /2")
.getValue(Integer.class); // 3

double num = parser.parseExpression("8.0 / 4e0 / 2")
.getValue(Double.class); // 1.0

//Modulus
int num = parser.parseExpression("7 % 2")
.getValue(Integer.class); // 1

int num = parser.parseExpression("8 / 5 % 2")
.getValue(Integer.class); // 1

//Operator precedence
int num = parser.parseExpression("1+2-3*4")
.getValue(Integer.class); // -9
Example of all Operator in SpEL
import org.springframework.expression.ExpressionParser;  
import org.springframework.expression.spel.standard.SpelExpressionParser;  
    
public class Simple {  
public static void main(String[] args) {  
ExpressionParser parser = new SpelExpressionParser();  
  
//arithmetic operator  
System.out.println(parser.parseExpression("'Hello'+'?'").getValue());  
System.out.println(parser.parseExpression("15 * 20/2").getValue());  
System.out.println(parser.parseExpression
("'Today is: '+ new java.util.Date()").getValue());
  
//logical operator  
System.out.println(parser.parseExpression("true and false").getValue());  
  
//Relational operator  
System.out.println(parser.parseExpression("'john'.length()==4").getValue());  
}  
}

Output

Previous Home Next