jsp 中 使用c:forEach 標籤中遍歷map集合

前言

在控制層使用如下代碼往jsp傳了一個xxxMap集合

new ModelAndView("/xxx/xxx.jsp").addObject("xxxMap",xxxMap);

以Map<String,User>說明用法

public class User{

	protected String  id; 		
	protected String  name; 		
	protected String  mobile; 		
	protected String  password; 	

	public void setId(String id) {this.id = id;}
	public String getId() {
		return this.id;
	}
	
	public void setName(String name) {this.name = name;}
	public String getName() 
	{
		return this.name;
	}

	public void setMobile(String mobile) {this.mobile = mobile;}
	public String getMobile() 
	{
		return this.mobile;
	}

    public void setPassword(String password) {this.password = password;}
	public String getPassword() 
	{
		return this.password;
	}

在jsp中中遍歷xxxmap<String,User> userMap

            <!-- jstl標籤庫中foreach標籤 -->
            <c:forEach items="${userMap}" var="item">
                <tr>
                 <!-- 展示其中一個key下的value,也就是User對象實例 -->
                    <td>${item.value.id}</td>
                    <td>${item.value.name}</td>
                    <td>${item.value.mobilel}</td>
                    <td>${item.value.password}</td>
                </tr>
            </c:forEach>

問題解決~

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章