Struts2中iterator標籤遍歷map總結

2021-08-26 21:35:47 字數 2580 閱讀 1616

public

classmapactionextendsactionsupport

); listmap=newhashmap>();

listlist1=newarraylist();

list1.add(newstudent(newlong(1),"20034140201","張三1","男",25));

list1.add(newstudent(newlong(2),"20034140202","張三2","男",25));

list1.add(newstudent(newlong(3),"20034140203","張三3","男",25));

listmap.put("class1",list1);

returnsuccess;

}publicmapgetmap()

public

voidsetmap(mapmap)

publicmapgetstudentmap()

public

voidsetstudentmap(mapstudentmap)

publicmapgetarraymap()

public

voidsetarraymap(maparraymap)

publicmap>getlistmap()

public

voidsetlistmap(map>listmap) }

<%@pagecontenttype="text/html;charset=utf-8"%>

<%@taglibprefix="s"uri="/struts-tags"%>

1.map中的value為string字串

"map"id="column">

"#column"/>

key:"key"/>

value:"value"/>

2.map中的value為student物件

"1"width="50%"cellspacing="0"cellpadding="0">

key=value id

***

age

"studentmap"id="column">

"#column"/>

"value.id"/>

"value.***"/>

"value.age"/>

3.map中的value為string陣列

"1"width="50%"cellspacing="0"cellpadding="0">

key=value id

numname

***age

"arraymap"id="column">

"#column"/>

"value[0]"/>

"value[1]"/>

"value[2]"/>

"value[3]"/>

"value[4]"/>

4.map中的value為list集合

"1"width="50%"cellspacing="0"cellpadding="0">

classid

num

name

***age

"listmap"id="column">

"total"value="#column.value.size"/>

"#column.value"status="s">

iftest="#s.first">"$">"#column.key"/>

if>

"id"/>

"num"/>

"name"/>

"***"/>

"age"/>

關鍵字使用: listdays ["monday","thursday","friday","sunday"]

使用 top 關鍵字:使用top 指代當前迭代元素,可以為物件

使用 last / first 關鍵字:#of.last用於判斷當前迭代到的元素是否為最後乙個元素,iterator 標籤中的status屬性代表當前迭代的位置;

使用

odd / even 關鍵字:odd關鍵字用來判斷當前迭代位置是否為奇數行

總結下,當宣告iterator的status屬性時,通過#statusname.method可以使用以下方法:

even : boolean - 如果當前迭代位置是偶數返回true

odd : boolean - 如果當前迭代位置是奇數返回true

count : int - 返回當前迭代位置的計數(從1開始)

index : int - 返回當前迭代位置的編號(從0開始)

first : boolean - 如果當前迭代位置是第一位時返回true

last : boolean - 如果當前迭代位置是最後一位時返回true

modulus(operand : int) : int - 返回當前計數(從1開始)與指定運算元的模數

Struts2中checkboxlist標籤的使用

selectedproducts name product.id list products listvalue name listkey id value 這裡分兩類,首先明確value的值應該是乙個list,用來顯示checkbox內那些需要先打勾 一類,當value的值是是乙個list bea...

Struts2字尾 深入Struts2

一 將action字尾變成html字尾 xmlversion 1.0 encoding utf 8 doctype struts public apache software foundation dtd struts configuration 2.1 en struts include file...

Struts2入門(一)Struts2簡介

本章簡要介紹一下struts2框架 1.概念 我們知道,springmvc框架是為了整合servlet設計的控制層框架,那麼還有其他的框架也實現了這個功能,那麼就是struts2。struts2是乙個基於mvc設計模式的web應用框架,它本質上相當於乙個servlet,在mvc設計模式中,strut...