public String random() {
StringBuffer applyNum=new StringBuffer();
applyNum.append("MC");
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat sf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
applyNum.append(sf.format(new Date()));
int random=(int) ((Math.random()*9000)+1000); // 随机四位数
applyNum.append(random);
applyNum.toString();
String aNum = applyNum.toString();
Map wy = new HashMap();
wy.put("applyNum", aNum);
WithdrawApply way = withdrawApplyService.queryApplyId(wy);
if (way != null) {
random();
}
return aNum;
StringBuffer applyNum=new StringBuffer();
applyNum.append("MC");
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat sf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
applyNum.append(sf.format(new Date()));
int random=(int) ((Math.random()*9000)+1000); // 随机四位数
applyNum.append(random);
applyNum.toString();
String aNum = applyNum.toString();
Map wy = new HashMap();
wy.put("applyNum", aNum);
WithdrawApply way = withdrawApplyService.queryApplyId(wy);
if (way != null) {
random();
}
return aNum;
}
如若想要去重 可以使用递归迭代 或者遍历