生成流水号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;
}
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;
}
相关文章推荐
- XHTML 1.0 的三种 XML 文档类型 DOCTYPE
- 查看tomcat的版本号
- Python中的时间
- org.xml.sax.SAXParseException
- android的消息机制——Handler机制
- MYEclipse Available Memory is low 警告 解决方法
- 使用javaMail发送邮件
- Markdown为写作而生
- SQL2005重装、SQL2005卸载
- 微信新增图文素材接口调用实例
- document.onclick是什么
- ios网络学习------2 用非代理方法实现同步post请求
- Mysql清理二进制日志的技巧
- Python学习之路四---面向对象
- LeetCode 007 Reverse Integer
- 非安装版Tomcat不能手动启动解决
- java中的Collection集合 List Set Map
- Ajax如何解决跨域问题
- oracle 查询最近执行过的 SQL语句
- Bundle version VS Bundle versions string