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());
        }*/
    }
  • 相关阅读:
    POJ 1475 推箱
    POJ 2253 Frogger
    POJ 1970 The Game
    POJ 1979 Red and Black
    HDU 1546 Idiomatic Phrases Game 求助!help!!!
    Fibonacci 1
    BZOJ 1041
    椭圆曲线质因数分解
    奇怪的高精度
    数论v2
  • 原文地址:https://www.cnblogs.com/inspred/p/8908701.html
Copyright © 2011-2022 走看看