实现效果:
代码样例:
工具类 UUIDMaker:
import java.util.UUID; import tk.mybatis.mapper.genid.GenId; public class UUIDMaker implements GenId<String> { public String genId(String table, String column) { UUID uuid = UUID.randomUUID(); String str = uuid.toString(); String temp = str.substring(0, 8) + str.substring(9, 13) + str.substring(14, 18) + str.substring(19, 23) + str.substring(24); return temp.toUpperCase(); } public static String getUUID() { UUID uuid = UUID.randomUUID(); String str = uuid.toString(); String temp = str.substring(0, 8) + str.substring(9, 13) + str.substring(14, 18) + str.substring(19, 23) + str.substring(24); return temp.toUpperCase(); } public static String[] getUUID(int number) { if (number < 1) { return null; } else { String[] ss = new String[number]; for (int i = 0; i < number; ++i) { ss[i] = getUUID(); } return ss; } } }