java后台字母数字拼接

//查询设置最大code值,没有设置默认值“YP0000001”
String hbid = serviceApiMapper.selectCode();
System.out.println(hbid);
String substr = hbid.substring(hbid.lastIndexOf("P") + 1);
Integer ii = Integer.parseInt(substr);
System.out.println(ii++);
String result = Integer.toString(ii);
int length = result.length();
StringBuffer sbf = new StringBuffer("YP");
String newnmb = StringUtils.leftPad(result, 7, '0');

StringBuffer append = sbf.append(newnmb);
String append2 = new String(append);
map.put("code", append2);
System.out.println("code添加到集合" + map.get("code"));

可以自行优化

posted @ 2021-09-14 19:38  小小菜包子  阅读(105)  评论(0)    收藏  举报