求问,下面的代码如何优化,我对el表达式实在不熟,求高手指点一二
把所有城市放到一个List里面,用循环替代一坨子的<li>...</li>语句,下面是一个例子:
<% java.util.List cities = new java.util.ArrayList(); cities.add("全国"); cities.add("北京"); cities.add("上海"); cities.add("广州"); cities.add("重庆"); pageContext.setAttribute("cities", cities); pageContext.setAttribute("searchCity", null); %> <c:forEach items="${cities}" var="city"> <p class='<c:if test="${(searchCity == null and city == '全国') or (searchCity == city)}">red</c:if>'>${city}</p> </c:forEach>
基于邢爱明童鞋的解决方法,后来我跟后台程序员研究出一种比较简单的写法,虽然我不清楚性能上有什么区别0.0.。。。
java.util.List cities = new java.util.ArrayList(); String[] a = {"北京","上海","深圳","广州","杭州","成都","南京","武汉","西安","厦门","长沙","苏州","天津","重庆","郑州", "青岛","合肥","福州","济南","大连","珠海","无锡","东莞","宁波","常州","沈阳","石家庄","昆明","南昌","南宁", "哈尔滨","海口","中山","惠州","贵阳","长春","太原","嘉兴","泰安","昆山","烟台","兰州","泉州"}; cities.addAll(Arrays.asList(a)); pageContext.setAttribute("cities", cities);
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(2)
把所有城市放到一个List里面,用循环替代一坨子的<li>...</li>语句,下面是一个例子:
基于邢爱明童鞋的解决方法,后来我跟后台程序员研究出一种比较简单的写法,虽然我不清楚性能上有什么区别0.0.。。。