互联网技术IT交流圈

EL表达式简单取值

2019-01-23  本文已影响6人  Java成长记_Camel

EL表达式简单取值
前提

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

  1. 直接获取数据
    后台直接传递 String name = “zyc”;

${name}

  1. 循环获取List数据
    //后台代码List集合
    List list = new ArrayList();
    list.add("I");
    list.add("L");
    list.add("O");
    list.add("V");
    list.add("E");


{list[0]},{list[1]},
{list[2]},{list[3]}


<c:forEach items="{list}" var="item" varStatus="status"> <li> <a target="_black">{item}
</a>
</li>
</c:forEach>

3.循环获取List < Object >数据
//后台数据
List<Student> list = new ArrayList<>();
list.add(new Student("Tom01",20));
list.add(new Student("Tom02",21));
list.add(new Student("Tom03",22));


<c:forEach items="{list}" var="item" varStatus="status"> <li> 姓名:{item.name},年龄:${item.age}
</li>
</c:forEach>

4.循环获取Map< String,List < Object > >数据
//后台数据
Map<String, List> map = new HashMap<>();
List<Student> list = new ArrayList<>();
list.add(new Student("Tom01",20));
list.add(new Student("Tom02",21));
list.add(new Student("Tom03",22));
map.put("studen01",list);

List<Student> list1 = new ArrayList<>();
list.add(new Student("Josh01",23));
list.add(new Student("Josh02",24));
list.add(new Student("Josh03",25));
map.put("studen02",list1);

List<Student> list2 = new ArrayList<>();
list.add(new Student("Jack01",26));
list.add(new Student("Jack02",27));
list.add(new Student("Jack03",28));
map.put("studen03",list2);


<c:forEach items="{map}" var="item">{item.key}
${item.value}
</c:forEach>


<c:forEach items="{map['student01']}" var="item" varStatus="status"> <li> 姓名:{item.name},年龄:${item.age}
</li>
</c:forEach>

上一篇下一篇

猜你喜欢

热点阅读