在程序中使String类型编号自增,例如001,002

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36537546/article/details/82888300
/*
bumen:定义的变量
bumenService:定义的类
按照自己定义的类就可以
*/
//定义一个字符串
String ii="00";
//查询出该字段最大数
String bumen1= bumenService.findMax();
//判断是否为空
if(bumen1 == null){
	//定义一个变量为1
	int bianhao = 1;
	//获取数字并格式化 == 返回语言环境的数值格式
	NumberFormat numberFormat = NumberFormat.getNumberInstance();
	//设置数值的最小位数
    numberFormat.setMinimumIntegerDigits(3);
    //数值是否分组显示
    numberFormat.setGroupingUsed(false);
    for (int time = 0 ; time < 1; time++){
    	String s = numberFormat.format(bianhao);
    	bianhao = Integer.parseInt(s);
    	bumen.setBianhao(s);
    	bianhao++;
    }
}else{
	//如果最大值大于等于10,则字符串为0
	//如果最大值小于等于10,则字符串为00
	if((Integer.parseInt(bumen1)+1)>=10){
		ii="0";
	}
	//把得到的数值转换成整数并且+1,再声明成String类型
	bumen.setBianhao(ii+(Integer.parseInt(bumen1)+1)+"");
}

猜你喜欢

转载自blog.csdn.net/qq_36537546/article/details/82888300