您的位置:首页 > 其它

生成流水号DEMO

2015-10-29 09:41 295 查看
public static void main(String[] args) {
String no=getMaxId();
System.out.println("流水号"+'\n'+no);

}

public static String getMaxId(){
SimpleDateFormat format= new SimpleDateFormat("yyyyMMdd");
String date=format.format(new Date());
String firstNo="000017";
String lastNo=firstNo+date+"001";
/**
* 此处可以冲数据库中查询然后进行比较,如果为空默认为lastno如果部位空
* 讲取出的流水号作为temp,然后截取,累加返回。
*/
StringBuffer sb=new StringBuffer();
String temp=lastNo.substring(lastNo.length()-3, lastNo.length());

if(Integer.parseInt(temp)>=1&&Integer.parseInt(temp)<999){
temp=String.valueOf(Integer.parseInt(temp)+1);
}
switch (temp.length()) {
case 1:
temp="00"+temp;
break;
case 2:
temp="0"+temp;
break;
default:
break;
}
lastNo=firstNo+date+temp;
return lastNo;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: