Java循环截取字符串或者list

    @Override
    public int groupBulkInsert(List list) {
        List> data = new ArrayList<>();
        List streee = new ArrayList<>();
        int sub = 2;
        int len = list.size();
        int mo = len % sub;
        if (mo != 0) {
            for (int i = 0; i < len - mo; i += sub) {
                streee = list.subList(i, i + sub);
                data.add(streee);
            }
            List tpm = list.subList(len - mo, len);
            data.add(tpm);
        } else {
            for (int i = 0; i < len; i += sub) {
                streee = list.subList(i, i + sub);
                data.add(streee);
            }
        }
        for (List arr : data) {
            studentMapper.groupBulkInsert(arr);
            System.err.println(arr);//遍历 数据插入时 
        }

    }

比如一个接口一次性最多接收100个,sub为100,list换成字符串也可以使用

你可能感兴趣的:(Java循环截取字符串或者list)