shiyunteng
6 天以前 7ffef0059ddf3d4a82de4a4a8999b4b2429fcda6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package com.by4cloud.platformx.business.utils;
 
import java.util.concurrent.atomic.AtomicLong;
import java.text.DecimalFormat;
 
public class ItemGeneratorUtil {
 
    private static final AtomicLong counter = new AtomicLong(0);
    private static final String PREFIX = "ITEM";
    // 定义格式:至少3位,不足补0
    private static final DecimalFormat formatter = new DecimalFormat("000");
 
    public static String nextId() {
        long num = counter.incrementAndGet();
        return PREFIX + formatter.format(num);
    }
    public static void main(String[] args) {
        System.out.println(nextId()); // ITEM001
        System.out.println(nextId()); // ITEM002
        System.out.println(nextId()); // ITEM003
    }
}