<h3>构造Map</h3>
<s:set name="foobar" value="#{'foo1':'bar1', 'foo2':'bar2'}" />
<p>The value of key "foo1" is <s:property value="#foobar['foo1']" /></p>
<p>不使用%:<s:url value="#foobar['foo1']" /></p>
<p>使用%:<s:url value="%{#foobar['foo1']}" /></p>
he value of key "foo1" is bar1 不使用%:#foobar['foo1'] 使用%:bar1
<validators>
<field name="intb">
<field-validator type="int">
<param name="min">10</param>
<param name="max">100</param>
<message>BAction-test校验:数字必须为${min}为${max}之间!</message>
</field-validator>
</field>
</validators>
public static void main(String[] args)
{
Map<String , Object> context = new HashMap<String , Object>();
Person person1 = new Person();
person1.setName("zhangsan");
Person person2 = new Person();
person2.setName("lisi");
Person person3 = new Person();
person3.setName("wangwu");
Person person4 = new Person();
person4.setName("zhaoliu");
context.put("person1", person1);
context.put("person2", person2);
context.put("person3", person3);
try
{
Object value = Ognl.getValue("name", context, person2);
System.out.println("ognl expression \"name\" evaluation is : " + value);
Object value2 = Ognl.getValue("#person2.name", context, person2);
System.out.println("ognl expression \"#person2.name\" evaluation is : " + value2);
Object value3 = Ognl.getValue("#person1.name", context, person2);
System.out.println("ognl expression \"#person1.name\" evaluation is : " + value3);
Object value4 = Ognl.getValue("name", context, person4);
System.out.println("ognl expression \"name\" evaluation is : " + value4);
Object value5 = Ognl.getValue("#person4.name", context, person4);
System.out.println("ognl expression \"person4.name\" evaluation is : " + value5);
// Object value6 = Ognl.getValue("#person4.name", context, person2);
// System.out.println("ognl expression \"#person4.name\" evaluation is : " + value6);
}
public static void main(String[] args)
{
OgnlContext context = new OgnlContext();
People people1 = new People();
people1.setName("zhangsan");
People people2 = new People();
people2.setName("lisi");
People people3 = new People();
people3.setName("wangwu");
context.put("people1", people1);
context.put("people2", people2);
context.put("people3", people3);
context.setRoot(people1);
try
{
Object value = Ognl.getValue("name.length()", context, context.getRoot());
System.out.println("people1 name length is :" + value);
Object upperCase = Ognl.getValue("#people2.name.toUpperCase()", context, context.getRoot());
System.out.println("people2 name upperCase is :" + upperCase);
Object invokeWithArgs = Ognl.getValue("name.charAt(5)", context, context.getRoot());
System.out.println("people1 name.charAt(5) is :" + invokeWithArgs);
Object min = Ognl.getValue("@java.lang.Math@min(4,10)", context, context.getRoot());
System.out.println("min(4,10) is :" + min);
Object e = Ognl.getValue("@java.lang.Math@E", context, context.getRoot());
System.out.println("E is :" + e);
}
public static void main(String[] args) throws Exception
{
OgnlContext context = new OgnlContext();
Classroom classroom = new Classroom();
classroom.getStudents().add("zhangsan");
classroom.getStudents().add("lisi");
classroom.getStudents().add("wangwu");
classroom.getStudents().add("zhaoliu");
classroom.getStudents().add("qianqi");
Student student = new Student();
student.getContactWays().put("homeNumber", "110");
student.getContactWays().put("companyNumber", "119");
student.getContactWays().put("mobilePhone", "112");
context.put("classroom", classroom);
context.put("student", student);
context.setRoot(classroom);
Object collection = Ognl.getValue("students", context, context.getRoot());
System.out.println("students collection is :" + collection);
Object firstStudent = Ognl.getValue("students[0]", context, context.getRoot());
System.out.println("first student is : " + firstStudent);
Object size = Ognl.getValue("students.size()", context, context.getRoot());
System.out.println("students collection size is :" + size);
System.out.println("--------------------------飘逸的分割线--------------------------");
Object mapCollection = Ognl.getValue("#student.contactWays", context, context.getRoot());
System.out.println("mapCollection is :" + mapCollection);
Object firstElement = Ognl.getValue("#student.contactWays['homeNumber']", context, context.getRoot());
System.out.println("the first element of contactWays is :" + firstElement);
System.out.println("--------------------------飘逸的分割线--------------------------");
Object createCollection = Ognl.getValue("{'aa','bb','cc','dd'}", context, context.getRoot());
System.out.println(createCollection);
Object createMapCollection = Ognl.getValue("#{'key1':'value1','key2':'value2'}", context, context.getRoot());
System.out.println(createMapCollection);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有