Code parsing for permission Table Design

Source: Internet
Author: User

The structure of the permission table has been described in the permission table design. Here I will describe the code

User table

</pre><pre name="code" class="html">@Entity@Table(name="user")public class User implements Serializable{    private static final long serialVersionUID = 6177417450707400228L;@Id@GeneratedValue(strategy = GenerationType.AUTO)    @Column(name="userid",nullable=false)private int userId;    @Column(name="username")private String userName;@Column(name="userpassword")    private String userPassword;    /*     * cascade:为级联操作,里面有级联保存,级联删除等,all为所有      * fetch:加载类型,有lazy和eager二种,     *   eager为急加载,意为立即加载,在类加载时就加载,lazy为慢加载,第一次调用的时候再加载,由于数据量太大,onetomany一般为lazy     * mappedBy:这个为manytoone中的对象名,这个不要变哦     *      * <UserRole>:为要获得的mappedBy的类     */    @OneToMany(fetch=FetchType.LAZY,mappedBy="user",cascade=CascadeType.ALL)private List<UserRole> listUserRole; public int getUserId() {return userId;}public void setUserId(int userId) {this.userId = userId;}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getUserPassword() {return userPassword;}public void setUserPassword(String userPassword) {this.userPassword = userPassword;}public List<UserRole> getListUserRole() {return listUserRole;}public void setListUserRole(List<UserRole> listUserRole) {this.listUserRole = listUserRole;}} 

Userrole table

@Entity@Table(name="userrole")public class UserRole implements Serializable{    private static final long serialVersionUID = 6177417450707400228L;@Id@GeneratedValue(strategy = GenerationType.AUTO)    @Column(name="id",nullable=false)private int id;@ManyToOne(fetch=FetchType.EAGER,cascade=CascadeType.ALL)@JoinColumn(name="userid")private User user;    @ManyToOne(fetch=FetchType.EAGER,cascade=CascadeType.ALL)@JoinColumn(name="roleid")private Role role;public int getId() {return id;}public void setId(int id) {this.id = id;}public User getUser() {return user;}public void setUser(User user) {this.user = user;}public Role getRole() {return role;}public void setRole(Role role) {this.role = role;}}
Role table

@Entity@Table(name="role")public class Role implements Serializable{private static final long serialVersionUID = 6177417450707400228L;   @Id@GeneratedValue(strategy = GenerationType.AUTO)    @Column(name="roleid",nullable=false)private int roleId;@Column(name="rolename")    private String roleName;@OneToMany(fetch=FetchType.LAZY,mappedBy="role",cascade=CascadeType.ALL)private List<UserRole> listUserRole;@OneToMany(fetch=FetchType.LAZY,mappedBy="role",cascade=CascadeType.ALL)private List<RolePermission> listRolePermission;public int getRoleId() {return roleId;}public void setRoleId(int roleId) {this.roleId = roleId;}public String getRoleName() {return roleName;}public void setRoleName(String roleName) {this.roleName = roleName;}public List<UserRole> getListUserRole() {return listUserRole;}public void setListUserRole(List<UserRole> listUserRole) {this.listUserRole = listUserRole;}public List<RolePermission> getListRolePermission() {return listRolePermission;}public void setListRolePermission(List<RolePermission> listRolePermission) {this.listRolePermission = listRolePermission;}}

Rolepermission table

@Entity@Table(name="rolepermission")public class RolePermission implements Serializable{    private static final long serialVersionUID = 6177417450707400228L;@Id@GeneratedValue(strategy = GenerationType.AUTO)    @Column(name="id",nullable=false)private int id;@ManyToOne(fetch=FetchType.EAGER,cascade=CascadeType.ALL)@JoinColumn(name="roleid")private Role role;@ManyToOne(fetch=FetchType.EAGER,cascade=CascadeType.ALL)@JoinColumn(name="permissionid")private Permission permission;public int getId() {return id;}public void setId(int id) {this.id = id;}public Role getRole() {return role;}public void setRole(Role role) {this.role = role;}public Permission getPermission() {return permission;}public void setPermission(Permission permission) {this.permission = permission;}}

Permission table

@Entity@Table(name="permission")public class Permission implements Serializable{        private static final long serialVersionUID = 6177417450707400228L;        @Id@GeneratedValue(strategy = GenerationType.AUTO)    @Column(name="permissionid",nullable=false)private int permissionId;    @Column(name="permission")private String permission;    @OneToMany(fetch=FetchType.LAZY,mappedBy="permission",cascade=CascadeType.ALL)private List<RolePermission> listRolePermission;    public int getPermissionId() {return permissionId;}public void setPermissionId(int permissionId) {this.permissionId = permissionId;}public String getPermission() {return permission;}public void setPermission(String permission) {this.permission = permission;}public List<RolePermission> getListRolePermission() {return listRolePermission;}public void setListRolePermission(List<RolePermission> listRolePermission) {this.listRolePermission = listRolePermission;}}

I have designed it here based on my permission table blog. In addition, I use onetoworkflow and manytoone. Here I can also use manytoone,

Write it according to your preferences.

Code parsing for permission Table Design

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.