Home > Java > javaTutorial > Example analysis of how jstl loops Map data in List in Javaweb

Example analysis of how jstl loops Map data in List in Javaweb

黄舟
Release: 2017-10-11 10:02:19
Original
1682 people have browsed it

This article mainly introduces the relevant information on how to loop the Map data in the List in jstl in javaweb. I hope this article can help everyone understand and master this part of the content. Friends who need it can refer to it

Detailed explanation of how jstl in javaweb loops Map data in List

The first way:

1: Background code ( Test)


List<Map<String, Object>> list = new ArrayList<Map<String,Object>>(); 
    Map<String, Object> map = null; 
    for (int i = 0; i < 4; i++) { 
      map = new HashMap<String, Object>(); 
      map.put("id", i); 
      map.put("name", "oo" + (i+1)); 
      list.add(map); 
    } 
    model.addAttribute("list", list);
Copy after login
Copy after login

2: Front page (test)


<c:forEach items="${list }" var="data"> 
        <p>${data.id} : ${data.name}</p> 
    </c:forEach>
Copy after login

3: Page Display content

Second way:

1: Background code (test)


List<Map<String, Object>> list = new ArrayList<Map<String,Object>>(); 
    Map<String, Object> map = null; 
    for (int i = 0; i < 4; i++) { 
      map = new HashMap<String, Object>(); 
      map.put("id", i); 
      map.put("name", "oo" + (i+1)); 
      list.add(map); 
    } 
    model.addAttribute("list", list);
Copy after login
Copy after login

2: Front page (test)


<c:forEach items="${list }" var="data"> 
        <c:forEach items="${data }" var="test"> 
          <p>${test.key} : ${test.value}</p> 
        </c:forEach> 
         
      </c:forEach>
Copy after login

3: Page display content

The above is the detailed content of Example analysis of how jstl loops Map data in List in Javaweb. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template