首页 > 其他 > 详细

生成流水号DEMO

时间:2015-10-29 10:58:03      阅读:195      评论:0      收藏:0      [点我收藏+]

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;  
          
    }

生成流水号DEMO

原文:http://www.cnblogs.com/lengzhijun/p/4919417.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!