Advertisement
package decodejava;
public class Employee
{
private String name;
private int telNo;
private char positionGrade;
private float yearsOfExp;
static String message;
public float getYearsOfExp()
{
return yearsOfExp;
}
public void setYearsOfExp(float yearsOfExp)
{
this.yearsOfExp = yearsOfExp;
}
public char getPositionGrade()
{
return positionGrade;
}
public void setPositionGrade(char positionGrade)
{
this.positionGrade = positionGrade;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getTelNo() {
return telNo;
}
public void setTelNo(int telNo)
{
this.telNo = telNo;
}
public static String getMessage()
{
return message;
}
public static void setMessage(String m)
{
message = m;
}
}
package decodejava;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
public class Utility {
public static void main(String[] args) throws NoSuchMethodException, SecurityException
{
Employee employee = new Employee();
StandardEvaluationContext stContext = new StandardEvaluationContext(employee);
SpelExpressionParser parser = new SpelExpressionParser();
//Accessing the setName() method using #this reference.
parser.parseRaw("#this.setName('Emp1')").getValue(stContext);
//Accessing the getName() method using #this reference.
System.out.println("Employee's Name : " + parser.parseRaw("#this.getName()").getValue(stContext));
//Accessing the setTelNo() method using #this reference.
parser.parseRaw("#this.setTelNo('1111111')").getValue(stContext);
//Accessing the getName() method using #this reference.
System.out.println("Employee's Tel No : " + parser.parseRaw("#this.getTelNo()").getValue(stContext));
//Accessing the setPositionGrade() method using #this reference.
parser.parseRaw("#this.setPositionGrade('A')").getValue(stContext);
//Accessing the getPositionGrade() method using #this reference.
System.out.println("Employee's position Grade : " + parser.parseRaw("#this.getPositionGrade()").getValue(stContext));
//Accessing the setYearsOfExp() method using #this reference.
parser.parseRaw("#this.setYearsOfExp('6.2')").getValue(stContext);
//Accessing the getYearsOfExp() method using #this reference.
System.out.println("Employee's Years of Exp : " + parser.parseRaw("#this.getYearsOfExp()").getValue(stContext));
//Accessing the static method setMessage() method using #this reference
System.out.println("Message is : " + parser.parseRaw("#this.setMessage('Hello')").getValue(stContext));
//Accessing the static method getMessage() method using #this reference.
System.out.println("Message is : " + parser.parseRaw("#this.getMessage()").getValue(stContext));
}
}
Advertisement
Employee's Name : Emp1
Employee's Tel No : 1111111
Employee's position Grade : A
Employee's Years of Exp : 6.2
Message is : Hello
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement