如何使用Java和MySQL为员工代码生成唯一的自定义序列ID

时间:2019-01-28 09:28:55

标签: java mysql

每当我创建新员工时,员工代码都应该是唯一的。例如,员工代码,例如E00001,E00002,E00003。

1 个答案:

答案 0 :(得分:0)

在MySQL中创建用于生成employeeId的序列:how ? here the info

//Get the sequence value and assign to local variable I am assuming value is 1 check below code

    String empIdNextSequence = String.valueOf(1);

            if (null != empIdNextSequence && empIdNextSequence.length() < 5)
            {
                int uuidNextSequenceLength = empIdNextSequence.length();
                for (int i = 0; i < 5 - uuidNextSequenceLength; i++)
                {
                    empIdNextSequence = "0".concat(empIdNextSequence);
                }
            }
            System.out.println("E"+empIdNextSequence);

将empIdNextSequence值设置为您的employeeCode