今天重新翻看了一下以前写的程序
String []goodsid=relatedgoodsid.split(",");
List<GoodsT> list=new ArrayList<GoodsT>();
String []picturelist;
ActionContext.getContext().getSession().remove("relatedgoods");
for(int i=0;i<goodsid.length;i++){
GoodsT list1=this.getGoodstserviceimpl().findGoodsById(goodsid[i]);
if(list1!=null){
picturelist=list1.getPictureurl().split(",");
list1.setPictureurl(picturelist[0]);
list.add(list1);
}
}
Map<String,Object>map=new HashMap<String,Object>();
map.put("related", list);
ActionContext.getContext().getSession().put("relatedgoods", map);
在前端用struts2标签显示的时候大家要注意判断先非空和数组大小吧
<s:if test="#session.relatedgoods.related!=null&&#session.relatedgoods.related.size()>0">
<div class="righttitle">商品组合</div>
<div class="goodszuhe">
<div class="detailzuhe">
<ul>
<s:iterator id="bean" value="#session.relatedgoods.related" status="related">
<li>
<div class="zuheimg">
<a href="GetGoodsdetailBygoodsid.action?goodsid<s:property value="goodsid"/>"><img src="<%=basePath %>Uploads/<s:property value="pictureurl"/>"/></a>
<div class="txt"><input type="checkbox" id="relatedgoodsid" name="relatedgoodsid" value="<s:property value="goodsid"/>" /><s:property value="goodsname"/></div>
</div>
</li>
</s:iterator>
</ul>
</div>
<div class="detailzuheinfo">
<input id="buyzuhe" name="buyzuhe" value="购买此组合" type="button"/>
</div>
</div>
</s:if>