编号的后6位是固定的6位数,新增一条自动+1,高位补0的实现

项目中遇到一个业务情况,编号递增且是6位整数。代码自动生成,具体的实现方法如下:
public static String maxRuleCode(String code) {
String maxcode = “”;
if(code == null){
maxcode = “QRC000001”;
} else {
int parseInt = Integer.parseInt(code.substring(3, 9)) + 1;
maxcode =”QRC” + String.format(“%6d”, parseInt).replace(” “, “0”);
}
return maxcode;
}

猜你喜欢

转载自blog.csdn.net/v_axis/article/details/78051074