问答详情
源自:8-8 使用Cookie实现保存商品浏览记录

id相同时cookie重复问题?

求怎样改进id重复的问题?试了试大家的代码,自己加进去还是不行,不知道加到哪里?

提问者:Atheny 2016-06-21 18:06

个回答

  • 慕盖茨9747674
    2016-12-12 10:07:07

    Public ArrayList<Items> getViewList(String list){
           ArrayList<Items> itemList = new ArrayList<Items>();
               ArrayList<Integer> ls = new ArrayList<Integer>();
               String[] arr=list.split(",");
               int iCount=5;
               if(list!=null&&list.length()>0){
                   for(int i=arr.length-1;i>=0;i--){
                      if(ls!=null&&!ls.isEmpty()){
                         if(ls.contains(Integer.parseInt(arr[i]))){
                            continue;
                         }else{
                            ls.add(Integer.parseInt(arr[i]));
                         }
                      }else{
                         ls.add(Integer.parseInt(arr[i]))
                      }
                     }
                   if(ls.size()<=iCount){
                      for(Integer i:ls){
                         itemList.add(getItemById(id));
                      }    
                   }else{
                      for(int i=0;i<iCount;i++){
                         itemList.add(getItemById(ls.get(i)));
                      }
                   }
                   return itemList;
               }else{
                   return null;
               }
    }


  • 小周先森57410
    2016-07-04 13:09:31

    同求啊!!

  • 94cc3447758
    2016-06-22 10:09:26

    能把你的操作过程描述得再详细些?