根据页面传的code 对应数据库的code 为 多对 一

@org.junit.Test
public void tt (){

System.out.println(ifresultStr("1,2,3,4,5,6,7,8,9"));
}




public static String ifresultStr(String id){
String numo="0";
if(id!=null&&id!=""){
String ids[] = id.split(",");
String resultStr = "";
for (int i = 0; i < ids.length; i++) {
if (ids[i].equals("1")) {
resultStr += "1,";
} else if (ids[i].equals("2")) {
resultStr += "2,";
} else if (ids[i].equals("3")) {
resultStr += "2,";
} else if (ids[i].equals("4")) {
resultStr += "2,";
} else if (ids[i].equals("5")) {
resultStr += "2,";
} else if (ids[i].equals("6")) {
resultStr += "2,";
} else if (ids[i].equals("7")) {
resultStr += "3,";
} else if (ids[i].equals("8")) {
resultStr += "3,";
} else if (ids[i].equals("9")) {
resultStr += "3,";
} else if (ids[i].equals("10")) {
resultStr += "3,";
} else if (ids[i].equals("11")) {
resultStr += "4,";
} else if (ids[i].equals("12")) {
resultStr += "4,";
} else if (ids[i].equals("13")) {
resultStr += "5,";
} else if (ids[i].equals("14")) {
resultStr += "5,";
}
}
//去除重复数字 例如 1,2,2,2,2,2,3,3,3 去除完 结果== 1,2,3
String[] array = resultStr.split(",");
StringBuilder sb = new StringBuilder();
for (String str : array) {
if(sb.indexOf(str) != -1){
continue;
}
sb.append(str).append(",");
}
String newStr = sb.toString().substring(0,sb.length() - 1);
return newStr ;
}
return numo;
}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。