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());
        }*/
    }
  • 相关阅读:
    vue 实现左侧分类列表,右侧文档列表
    C# string数组与list< string >的相互转换
    c# List<string>的用法
    类数组 数组
    事件
    js封装方法和浏览器内核
    dom
    try...catch es5
    data对象 定时器
    call apply 原型 原型链
  • 原文地址:https://www.cnblogs.com/inspred/p/8908701.html
Copyright © 2011-2022 走看看