ognl

package com.lgg.ognl.testdao;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;


import com.lgg.ognl.test.SClass;
import com.lgg.ognl.test.School;
import com.lgg.ognl.test.Student;


import ognl.Ognl;
import ognl.OgnlException;


public class OgnlTest2 {


public static void main(String[] args) throws OgnlException, ParseException {
// TODO Auto-generated method stub
//test();
test2();


}



public static void test() throws OgnlException{

School school1=new School();
SClass java1=new SClass();
java1.setCname("java 01");
SClass java2=new SClass();
java2.setCname("java 02");
List<SClass> classes= new ArrayList<SClass>();
classes.add(java1);
classes.add(java2);
school1.setClasses(classes);
Object object=Ognl.getValue("classes.{cname}", school1);
System.out.println(object);

}
public static void test2() throws ParseException, OgnlException{

SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");

Student s=new Student("zhansan", 23.0f,format.parse("2013-03-04") , null, 90);
Student s2=new Student("lisi", 20.0f,format.parse("2005-07-04") , null, 80);
Student s3=new Student("zhaosi", 22.0f,format.parse("2004-06-04") , null, 88);
 
List<Student> m=new ArrayList<Student>();
m.add(s);
m.add(s2);
m.add(s3);
SClass cla=new SClass();
Ognl.setValue("students", cla, m);
Scanner sc =new Scanner(System.in);
int temp=sc.nextInt();

Iterator<String> it= (Iterator<String>) Ognl.getValue("students.{?#this.scores>="+temp+"}.{sname}.iterator", cla);
while(it.hasNext()){
System.out.println(it.next());

}
/* ArrayList list = (ArrayList) Ognl.getValue("students.{?#this.scores>="+temp+"}", cla);
for (int i = 0; i < list.size(); i++) {
Student stu =(Student) list.get(i);
System.out.println(stu.getSname()+"  "+stu.getAge()
+"  "+format.format(stu.getBday())
+"  "+stu.getScores());
}*/
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值