A packaging method, implemented by a Map, here is resolved according to the bean class seq field, divided into several list
private LinkedHashMap<String,List<HandleInfo>> groupListBySeq(List<HandleInfo> list) {
LinkedHashMap<String,List<HandleInfo>> map = new LinkedHashMap<String,List<HandleInfo>>();
for (HandleInfo bean : list) {
if(map.containsKey(bean.getSeq())){
List<HandleInfo> subList = map.get(bean.getSeq());
subList.add(bean);
}else{
List<HandleInfo> subList = new ArrayList<HandleInfo>();
subList.add(bean);
map.put(bean.getSeq(), subList);
}
}
return map;
}
Then it can be traversed to get to the Map:
LinkedHashMap<String,List<HandleInfo>> map = groupListBySeq(needUpdateHandleInfoList);
//遍历集合
for(Map.Entry<String, List<HandleInfo>> entry : map.entrySet()){
List<HandleInfo> list=(List<HandleInfo>)entry.getValue();
HandleInfo bean0 = new HandleInfo();
if(null != list || !list.isEmpty()){
bean0 = list.get(0);
}
for(HandleInfo handleInfoModel : list){
...
}
}
The above method is grouped by database fields, and explain how much data set into the average amount
java code simply get the set of parameters can be resolved:
For example, the following is a method, not in accordance with the list as a set of packets 1000
List<String> values = new ArrayList<String>();
String[] configSeqArray = StringUtils.split(configSeq,',');
for (String str : configSeqArray) {
values.add(str);
}
List<Collection<String>> configSeqs = CollectionUtil.splitCollection(values, 1000);
Copy written by co-workers split the collection method
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class CollectionUtils {
public static List<Collection<String>> splitCollection(Collection<String>values , int size) {
List<Collection<String>> result = new ArrayList<Collection<String>>();
if(values.size() <= size ){
result.add(values);
}else{
int count =0;
Collection<String> subCollection= null;
for(String s:c){
if(subCollection == null){
subColletion = new ArrayList<String>();
result.add(subColletion);
}
subCollection.add(s);
count++;
if(count == size){
count =0;
subCollectiion = null;
}
}
}
}
}
This method can be applied to solve Oracle select in over 1000 being given, specific reference: https://smilenicky.blog.csdn.net/article/details/87922878