首页 > 代码库 > springmvc+hibernate在实体类中设置外键

springmvc+hibernate在实体类中设置外键

1.表User id主键,username,password,dept...

表Attendence id主键,uid外键,time...

 1 @ManyToOne
 2     @JoinColumn(name = "uid",referencedColumnName="id")
 3     private User user;
 4 
 5     public User getUser() {
 6         return user;
 7     }
 8 
 9     public void setUser(User user) {
10         this.user = user;
11     }

2.查询时只需  u.user.id即可

springmvc+hibernate在实体类中设置外键