public static void main( String[] args ) throws Exception {
//创建配置文件并且向配置文件中写入字符串的分隔符
Properties props = new Properties();props.setProperty("separator", "/");
//实现分隔符号的设置,默认为“”,下面不写当面设置无效
IdentifierGenerator gen = new UUIDHexGenerator();( (Configurable) gen ).configure(Hibernate.STRING, props, null);
IdentifierGenerator gen2 = new UUIDHexGenerator();
( (Configurable) gen2 ).configure(Hibernate.STRING, props, null);
//遍历打印获得的id 主键生成策略 getIP() + getJVM() + getHiTime() +getLoTime() + getCount()
/*
单机情况下只有getJVM() + getLoTime()这两项发生变化
getCount() 每次都是从1开始计数
*/
for ( int i=0; i<10; i++) {
String id = (String) gen.generate(null, null);System.out.println(id);
String id2 = (String) gen2.generate(null, null);
System.out.println(id2);
}
}