脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-JSTL解析――003――core标签库02,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。 上一节主要讲解了<c:if/><c:choose/><c:when/><c:otherwise><c:out/>标签的使用,下面继续讲解其它标签的使用技巧
1、<c:foreach>标签
1)有时候为了效果,只显示偶数行信息
<table>
<c:forEach VAR="num" begin="2" end="100" step="2">
<tr>
[html]
<td>${num}</td>
[html]
</tr>
</c:forEach>
</table>
var是定义的一个变量,最开始将2赋值给它,step是没进行一次加2,当等于100的时候结束
2)遍历List值
[html]
<table>
<c:forEach var="PErson" ITems="${personList}">
<tr>
[html]
<td>${person.id}</td>
[html]
<td>${person.name}</td>
[html]
</tr>
</c:forEach>
</table>
personList是attribute变量,一个List值,最好是有泛型规范的,Person是一个变量,系统会自动将它转换没你personList里面对象类型
3)遍历Map值
Map虽然也是集合类,但是有雨Map是存储的是一对属性,因此遍历Map和List有些不同
[html]
<table>
<c:forEach var="paramnumber" items="$paramnumberMap}">
[html]
<tr>
[html]
<td>${paramnumber.key}</td>
<td>${paramnumber.value}</td>
[html] view plaincopyprint?
</tr>
</c:forEach>
</table>
4)forEac标签varstatus属性
有时候是不是有这种苦恼,需要序号,或者说需要将不同行显示不同的效果等
[html]
<pre name="code" class="html"><table>
<c:forEach var="person" items="${personList}" varStatus="varsort">
<tr bgcolor="${varSort.index%2==1?'red':'blue'}"></pre><pre name="code" class="html"><td>${varSort}</td></pre><pre name="code" class="html"><td>${person.id}</td></pre><pre name="code" class="html"><td>${person.name}</td></pre><pre name="code" class="html"></tr>
</c:forEach>
</table></pre>这样奇偶行就会出现红蓝颜色差别了,还有序号,是不是有点不相信,那就亲手试试看
<pre></pre>
<p></p>
<pre></pre>
<pre name="code" class="html">varStatus还有自己的属性,index(返回当前对象是第几个对象)、count(返回遍历了多个对象)、First(返回当前对象是否是第一个对象)、last类推、current(返回当前遍历的对象)、degin、end、step。</pre>
<pre name="code" class="html"></pre>
<br>
<p></p>
觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的javascript代码实例教程-JSTL解析――003――core标签库02全部内容,希望文章能够帮你解决javascript代码实例教程-JSTL解析――003――core标签库02所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。