角色(用户组),用户多对多。
角色实体配置:
private Set<TAuthUser> users; @ManyToMany
@JoinTable(name="t_auth_user_role",joinColumns={@JoinColumn(name="role_id")},inverseJoinColumns={@JoinColumn(name="user_id")})//配置一方
public Set<TAuthUser> getUsers() {
return users;
} public void setUsers(Set<TAuthUser> users) {
this.users = users;
}
用户实体配置:
private Set<TAuthRole> roles; @ManyToMany(mappedBy="users")//"users"为在角色表中名称
public Set<TAuthRole> getRoles() {
return roles;
} public void setRoles(Set<TAuthRole> roles) {
this.roles = roles;
}
測试生成角色表:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd2ludGVyc3dlZXRzdWdhcg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
用户表:
角色用户关联表: