简体   繁体   English

在字符串中生成唯一员工代码

[英]Generate Unique Employee code in String

I am implementing Employee Management System in Java.我正在用 Java 实现员工管理系统。 I want employee code to be auto generated on new employee registration and I should be in predefined format.我希望在新员工注册时自动生成员工代码,我应该采用预定义的格式。 I don't want to use auto incremented integer key as a employee ID.我不想使用自动递增的整数键作为员工 ID。 I am using MySQL Database and JDBC API to connect to MySQL.我正在使用 MySQL 数据库和 JDBC API 连接到 MySQL。 Please suggest me a solution.请建议我一个解决方案。

如果 ID 的长度无关紧要,只需使用 java.util.UUID 生成通用唯一标识符。

There can be many approaches to generate an employee Id.I am recommending following most commonly used methods.可以有多种方法来生成员工 ID。我推荐以下最常用的方法。

1) Timestamp Based :- Use UUID from java.util.UUID to generate random ID's based on host and current time. 1)基于时间戳:- 使用 java.util.UUID 中的 UUID 根据主机和当前时间生成随机 ID。

UUID uuid = UUID.randomUUID(); 

2) Custom Information Based 2)基于自定义信息

If you want an employeeId to be generated using Company Initials/Employee's Personal Information,如果您希望使用公司姓名首字母/员工个人信息生成员工 ID,

  • Use employee's username and date of birth使用员工的用户名和出生日期
  • Take a namespace identifier(can be your organisation's name)取一个命名空间标识符(可以是您组织的名称)

    With the hash of unique identifier and username of employee,使用员工的唯一标识符和用户名的哈希值,

     String source = namespace + username + dateofbirth; byte[] bytes = source.getBytes("UTF-8"); UUID uuid = UUID.nameUUIDFromBytes(bytes);

3) Use Company Initials : Lets say your company initials are XYZ.Use a random number generator function to generate any 5 or 6 digit number. 3)使用公司缩写:假设您的公司缩写是 XYZ。使用随机数生成器函数生成任何 5 或 6 位数字。 Eg.例如。 XYZ47899 XYZ47899

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM