日期:2014-05-18 浏览次数:20611 次
public String addGoodsToCar() throws Exception {
int id = Integer.parseInt(goodsid);
Goods mycargoods = goodsService.getGoods(id);
list.add(mycargoods);// 更新list
ActionContext.getContext().getSession()
.put("mycarlist", list);// 更新session
ActionContext.getContext().getSession().put("mycarsize", list.size());
mycarsize = list.size();
System.out.println("listsize=" + list.size());
return super.execute();
}
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class ListTest1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
List<ObjectItem> list = new ArrayList<ObjectItem>();
list.add(new ObjectItem(2));
list.add(new ObjectItem(2));
list.add(new ObjectItem(2));
list.add(new ObjectItem(3));
Set<ObjectItem> s = new HashSet<ObjectItem>();
for(ObjectItem o : list){
s.add(o);
}
Iterator<ObjectItem> it = s.iterator();
while(it.hasNext()){
System.out.println(it.next().getId());
}
}
}
class ObjectItem {
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public ObjectItem(Integer id){
this.id = id;
}
public boolean equals(Object obj) {
if(obj instanceof ObjectItem) {
ObjectItem n = (ObjectItem)obj;
if(id == n.id) {
return true;