打开 JPA 面板
View→Tool Windows→Persistence(如果没有,先确保项目已启用 JPA)生成实体
右键项目名 →
Generate Persistence Mapping→By Database Schema选择已配置的数据库连接 → 勾选需要生成实体的表(如
EMPLOYEE)配置生成选项:
Package:指定实体类存放的包(如
com.example.entity)Options:勾选
Generate JPA annotations和Generate column name annotationsCustomize mappings:可手动调整字段类型(如将
NUMBER映射为Long)
完成生成
生成的实体类会自动出现在指定包下,示例:@Entity @Table(name = "EMPLOYEE") public class Employee { @Id @Column(name = "EMP_ID", precision = 10) private Long empId; @Column(name = "EMP_NAME", length = 50) private String empName; // 自动处理外键关联 @ManyToOne @JoinColumn(name = "DEPT_ID") private Department department; }
评论交流