伙计们我有一个域名客户我一直在使用默认的自动增量值或gorm来处理我的id。但是,现在我想改变id从自动生成6个字母数字字符,你知道他们必须是唯一的吗?那我怎么做呢?拜托?
gupuwyp21#
将id属性定义为objectid可以生成12个字母数字字符的id
v2g6jxz62#
跟随这个亲爱的:
public static String getAlphaNumbericRandom(int length) { String chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int numberOfCodes = 0;//controls the length of alpha numberic string String code = ""; while (numberOfCodes < length) { char c = chars.charAt((int) (Math.random() * chars.length())); code += c; numberOfCodes++; } return code; }
调用此方法并传递长度(例如4、5等)
2条答案
按热度按时间gupuwyp21#
将id属性定义为objectid可以生成12个字母数字字符的id
v2g6jxz62#
跟随这个亲爱的:
调用此方法并传递长度(例如4、5等)