zoukankan      html  css  js  c++  java
  • id生成工具类

    import java.util.Random;
    
    /**
     * 各种id生成策略
     * <p>Title: IDUtils</p>
     * <p>Description: </p>
     * <p>Company: www.itcast.com</p> 
     * @author    入云龙
     * @date    2015年7月22日下午2:32:10
     * @version 1.0
     */
    public class IDUtils {
    
        /**
         * 图片名生成
         */
        public static String genImageName() {
            //取当前时间的长整形值包含毫秒
            long millis = System.currentTimeMillis();
            //long millis = System.nanoTime();
            //加上三位随机数
            Random random = new Random();
            int end3 = random.nextInt(999);
            //如果不足三位前面补0
            String str = millis + String.format("%03d", end3);
            
            return str;
        }
        
        /**
         * 商品id生成
         */
        public static String genStringId() {
            //取当前时间的长整形值包含毫秒
            long millis = System.currentTimeMillis();
            //long millis = System.nanoTime();
            //加上两位随机数
            Random random = new Random();
            int end2 = random.nextInt(99);
            //如果不足两位前面补0
            String id = millis + String.format("%02d", end2);
            return id;
        }
        
        /**
         * long型id生成
         */
        public static long genLongId() {
            //取当前时间的长整形值包含毫秒
            long millis = System.currentTimeMillis();
            //long millis = System.nanoTime();
            //加上两位随机数
            Random random = new Random();
            int end2 = random.nextInt(99);
            //如果不足两位前面补0
            String str = millis + String.format("%02d", end2);
            long id = new Long(str);
            return id;
        }
        
        /*public static void main(String[] args) {
            for(int i=0;i< 100;i++)
            System.out.println(genItemId());
        }*/
    }
  • 相关阅读:
    Equivalent Sets HDU
    Chemical table CFR500 div2D(并查集)
    How do I create an installation log?
    Error 1937.An error occurred during the installation of assembly...
    InstallShield 版本转换
    Convert CString to TCHAR
    InstallShield : 如何查找编译后的 Merge Module存放路径
    Msi.h causes compilation error in vs2010
    区间调度(贪心)
    硬币问题(贪心)
  • 原文地址:https://www.cnblogs.com/inspred/p/8908701.html
Copyright © 2011-2022 走看看