zcx929666 2016-09-11 14:43 采纳率: 0%
浏览 1352
已结题

session写得购物车批量删除的问题

List批量删除 因为删除了一个 下标越界了 这个时候该怎么判断呢??

  • 写回答

6条回答

  • zcx929666 2016-09-11 14:42
    关注
    String[] indexs=index.split(",");//用逗号分割
            System.out.println("删除多个:"+index);
            int tempIndex=0;
            int preIndex=0;
            for (int i = 0; i < indexs.length; i++) {
                tempIndex=Integer.parseInt(indexs[i]);
                System.out.println("tempIndex1:"+tempIndex);
                System.out.println("preIndex:"+preIndex);
                tempIndex=tempIndex-preIndex;
                if(preIndex==1){//说明是最后一个了
                    tempIndex=0;
                }
                System.out.println("tempIndex2:"+tempIndex);
                int pid=cartList.get(tempIndex).getPid();
                System.out.println("产品名称:"+cartList.get(tempIndex).getPname());
                cartList.remove(tempIndex);//先移除List中的数据
                cartMap.remove(pid);//根据id移除map中的数据
                preIndex=tempIndex;
            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法