您现在的位置是:主页 > news > 江苏省住房和城乡建设厅政务网站/站长之家 seo查询

江苏省住房和城乡建设厅政务网站/站长之家 seo查询

admin2025/6/15 18:36:35news

简介江苏省住房和城乡建设厅政务网站,站长之家 seo查询,微网站开发系统,可商用图片素材网站多对多关联映射 需要添加一张数据表&#xff0c;用来关联 双方 一&#xff0c;单向多对多关联映射 1&#xff0c;在一端的bean类添加对方的属性 如 Category类 private Set<Item> itemsnew HashSet<Item>(); 2&#xff0c;修改该bean类对应的映射文件 Category.hbm…

江苏省住房和城乡建设厅政务网站,站长之家 seo查询,微网站开发系统,可商用图片素材网站多对多关联映射 需要添加一张数据表&#xff0c;用来关联 双方 一&#xff0c;单向多对多关联映射 1&#xff0c;在一端的bean类添加对方的属性 如 Category类 private Set<Item> itemsnew HashSet<Item>(); 2&#xff0c;修改该bean类对应的映射文件 Category.hbm…

多对多关联映射 需要添加一张数据表,用来关联 双方

一,单向多对多关联映射

  1,在一端的bean类添加对方的属性

    如 Category类

      private Set<Item> items=new HashSet<Item>();

  2,修改该bean类对应的映射文件

    Category.hbm.xml

      <set name="items" table="CATEGORY_ITEM" >
        <key>
          <column name="C_ID" />
        </key>
        <many-to-many class="com.m01.n2n.Item" column="I_ID"></many-to-many>
      </set>

      name: 对应本类的属性 items; 

      table: 中间表; column的name : 指的是中间表中 指向本bean类的数据表的 外键

      class: 对面bean类的全命名;  column : 中间表中 指向对面bean类的数据表的 外键

      

 


 

一, 双向多对多关联

  1,在一端的bean类添加对方的属性

    如 Category类

      private Set<Item> items=new HashSet<Item>();

     Item类

      private Set<Category> categorys=new HashSet<>();

  2,修改bean类对应的映射文件 

    Category.hbm.xml 

      <set name="items" table="CATEGORY_ITEM" >
        <key>
          <column name="C_ID" />
        </key>
        <many-to-many class="com.m01.n2n.Item" column="I_ID"></many-to-many>
      </set>

      name: 对应本类的属性 items; 

      table: 中间表; column的name : 指的是中间表中 指向本bean类的数据表的 外键

      class: 对面bean类的全命名;  column : 中间表中 指向对面bean类的数据表的 外键

    Item.hbm.xml   

      <set name="categorys" table="CATEGORY_ITEM">
        <key>
          <column name="I_ID"></column>
        </key>
        <many-to-many class="com.m01.n2n.Category" column="C_ID"/>
      </set>

    同上;

转载于:https://www.cnblogs.com/m01qiuping/p/6384782.html