//每组数据的个数
private static final int everyGroupNum=9;
public static StringBuffer getIn() {
//123,234,345,456,567,678,789
String patientAllId="123,234,345,456,567,678,789,8910,91011,101112";
String patientid="";
StringBuffer buffer=new StringBuffer();
if(ElaneUtil.isNotEmpty(patientAllId)){
String[] array=patientAllId.split(",");
//数组总长度
int len=array.length;
//分组数
int groupCount=len/everyGroupNum;
for(int k=0;k<groupCount;k++){
patientid="";
for(int i=(k*everyGroupNum);i<(k*everyGroupNum+everyGroupNum);i++){
if(i==k*everyGroupNum){
//每组的第一个数组
patientid="'"+array[i].trim()+"'";
}else{
patientid=patientid+","+"'"+array[i].trim()+"'";
}
}
buffer.append(" and in("+patientid+")");
}
if(len%everyGroupNum != 0){
//未整除
patientid="";
//处理最后一组数据
for(int j=(groupCount*everyGroupNum);j<len;j++){
if(j==groupCount*everyGroupNum){
//每组的第一个数组
patientid="'"+array[j].trim()+"'";
}else{
patientid=patientid+","+"'"+array[j].trim()+"'";
}
}
buffer.append(" and in("+patientid+")");
}
}
return buffer;
}
java 根据每个分组个数,分解数组.
最新推荐文章于 2024-08-21 02:26:10 发布