我有一个班级,让员工说如下:

public class Employee{
    ... Other attributes ...
    @Column @Enumerated(EnumType.Ordinal)
    private Gender gender;

    @Column @Enumerated(EnumType.Ordinal)
    private EmployeeType employeeType;
    ... Getters & Setters ...
}


我的员工表是这样的。

Employee{
    ... other columns ....
    gender int,
    employeetype int,
    ...
}


我有一个通用的查询表查询

Lookups{
    id long,
    lookName String,
    lookId int,
    lookValue String
}


我希望Gendle和EmployeeTypes可以按以下方式通过休眠方式保留在Lookups表中,如下所示:

+--+-------------+---------+------------+
|ID|LOOKUPNAME   |LOOKUPID | LOOKUPVALUE|
+--+-------------+---------+------------+
+--+-------------+---------+------------+
|1 | GENDER      | 1       | MALE       |
+--+-------------+---------+------------+
|2 | GENDER      | 2       | FEMALE     |
+--+-------------+---------+------------+
|3 | EMPLOYEETYPE| 1       | TEAM MEMBER|
+--+-------------+---------+------------+
|4 | EMPLOYEETYPE| 2       | TEAM LEADER|
+--+-------------+---------+------------+
|5 | EMPLOYEETYPE| 3       | MANAGER    |
+--+-------------+---------+------------+

最佳答案

创建Lookups类。然后,对于Employee类的Gender和EmployeeType字段,将它们替换为Lookups字段。然后删除枚举注释。

10-08 00:00