Java循環截取字符串或者list

    @Override
    public int groupBulkInsert(List<StudentDto> list) {
        List<List<StudentDto>> data = new ArrayList<>();
        List<StudentDto> 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<EmergencyExpertExcelDto> arr : data) {
            studentMapper.groupBulkInsert(arr);
            System.err.println(arr);//遍歷 數據插入時 
        }

    }

比如一個接口一次性最多接收100個,sub爲100,list換成字符串也可以使用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章