EL表达式简单取值
EL表达式简单取值
前提
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
- 直接获取数据
后台直接传递 String name = “zyc”;
${name}
- 循环获取List数据
//后台代码List集合
List list = new ArrayList();
list.add("I");
list.add("L");
list.add("O");
list.add("V");
list.add("E");
{list[1]},
{list[3]}
<c:forEach items="{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="{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="{item.key}
${item.value}
</c:forEach>
<c:forEach items="{item.name},年龄:${item.age}
</li>
</c:forEach>