zoukankan      html  css  js  c++  java
  • 25.OGNL与ValueStack(VS)-集合对象进阶

    转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html

    首先在LoginAction中增加如下字段并提供相应的get/set方法:
    private List studentList = new ArrayList();
    然后再在execute中为其初始化赋值,代码如下:
    studentList.add(new Student("jack", 20, 86.0f));

    studentList.add(new Student("lily", 22, 96.5f));

    studentList.add(new Student("tom", 23, 56.5f));

    最后在loginSuc.jsp中增加如下代码:
    获取List中的Student对象:<s:property value="studentList"/><br>

    利用投影获取List中的name属性:<s:property value="studentList.{name}"/><br>

    利用投影获取List中的age属性:<s:property value="studentList.{age}"/><br>

    利用投影获取List中的第一个对象的name属性:<s:property value="studentList.[0]{name}"/>   或者<s:property value="studentList.{name}[0]"/><br>

    利用选择获取List中grade>60的student信息:

    <s:property value="studentList.{?#this.grade>60}"/><br>

    利用选择获取List中grade>60的student名字信息:

    <s:property value="studentList.{?#this.grade>60}.{name}"/><br>

    利用选择获取List中grade>60的第一个student名字信息:

    <s:property value="studentList.{?#this.grade>60}.{name}[0]"/><br>

    利用选择获取List中grade>60的第一个student名字信息(链表):

    <s:property value="studentList.{^#this.grade>60}.{name}"/><br>

    利用选择获取List中grade>60的最后一个student名字信息(链表):

    <s:property value="studentList.{$#this.grade>60}.{name}"/><br>

    说明:这里重点是说明?#的使用,结合此例来看,studentList中有许多Stutdent对象,我们可以用条件来限制取哪些对象,这些条件必须以?#开始,并且条件要用{}括起。而this是指在判断studentList中的对象是否符合条件的当前对象。?#是指取出符合条件的所有Student对象,而^#是指取出符合条件的第一个对象,$#是指取出符合条件的最后一个对象。

  • 相关阅读:
    Android传递中文参数方法(之一)
    配置类与yaml
    修改ip失败,一个意外的情况处理方法
    oracle 自增序列与触发器
    Excel导入数据带小数点的问题
    数据库null与空的区别
    小米手机无法打开程序报错Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication的解决办法
    gradle类重复的问题解决方法
    windowSoftInputMode属性讲解
    android studio 的配置
  • 原文地址:https://www.cnblogs.com/sharpest/p/5582882.html
Copyright © 2011-2022 走看看