zoukankan      html  css  js  c++  java
  • 用户、角色、权限三者多对多用hibernate的一对多注解配置

    用户、角色、权限三者多对多用hibernate的一对多注解配置

    //权限表
    @Table(name = "p")
    public class P {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "p_id", unique = true, nullable = false)
    private Integer id;
    @OneToMany(mappedBy = "p",cascade=CascadeType.ALL)
    private Set<PR> pr = new HashSet<PR>();
    /*省略所有get、set方法及其他列*/
    }
    //权限角色表
    @Entity
    @Table(name = "pr")
    public class PR {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "pr_id", unique = true, nullable = false)
    private Integer id;
    @ManyToOne
    @JoinColumn(name = "r_id")
    private R r;
    @ManyToOne
    @JoinColumn(name = "p_id")
    private P p;
    /*省略所有get、set方法及其他列*/
    }
    //角色表
    @Entity
    @Table(name = "r")
    public class R {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "r_id", unique = true, nullable = false)
    private Integer id;
    @OneToMany(mappedBy = "r",cascade=CascadeType.ALL)
    private Set<PR> pr = new HashSet<PR>();
    @OneToMany(mappedBy = "r",cascade=CascadeType.ALL)
    private Set<RU> ru = new HashSet<RU>();
    /*省略所有get、set方法及其他列*/
    }
    //角色用户关系表
    @Entity
    @Table(name = "ru")
    public class RU {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ru_id", unique = true, nullable = false)
    private Integer id;
    @ManyToOne
    @JoinColumn(name = "r_id")
    private R r;
    @ManyToOne
    @JoinColumn(name = "u_id")
    private U u;
    /*省略所有get、set方法及其他列*/
    }
    //用户表
    @Entity
    @Table(name = "u")
    public class U {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "u_id", unique = true, nullable = false)
    private Integer id;
    @OneToMany(mappedBy = "u",cascade=CascadeType.ALL)
    private Set<RU> ru = new HashSet<RU>();
    /*省略所有get、set方法及其他列*/
    }

    数据库图片示例:

    结果如上。(P《权限表》、R《角色表》、U《用户表》、PR《权限角色关系表》、RU《角色用户关系表》)

  • 相关阅读:
    github上fork的项目,如何同步原作者更新的内容?
    设计模式-简单工厂模式详解
    设计模式-建造者模式详解
    设计模式-原型模式详解
    设计模式-单例模式详解
    SqlServer断开所有连接
    Winform重写键盘按键事件
    从拖拉控件编程到面向设计编程(一)
    Springboot vue 前后分离 跨域 Activiti6 工作流 集成代码生成器 shiro权限
    java 微信自定义菜单 java微信接口开发 公众平台 SSM redis shiro 多数据源
  • 原文地址:https://www.cnblogs.com/xiaocao1434/p/5245832.html
Copyright © 2011-2022 走看看