• mapper.xml一对一 对多


    建表开始 

    一对一

    1---外键在附属表 ,建实体类 实体类不要有那个外键 ,具体关联查找的bean属性在附属实体类里建,即外键在哪个实体类属性就在哪建!

    2---两个bean建好,mapper接口 mapper.xml配置rsultmap

    <resultmap type="附属表bean的具体类路径 id=“xxx”">

    <result column="表的字段"  property="实体类字段"/>

    。。。。

      <association property="附属表的实体bean属性名称"  javaType="附属表的实体bean的类路径">

    <id property="关联查找的bean的主键字段表示"  column="对应的表主键"/>

    <result column="表的字段"  property="实体类字段"/>

    。。。。

    </association >

    </resultmap>

    一对多

    1--表建好 外键在多的一方  实体类建好  关联查找的list集合在一的一方 与上面相反

    2--mapper接口mapper.xml

    <resultmap type="一的一方类路径“ id=“xxx”">

    <result column="表的字段"  property="实体类字段"/>

    。。。。

     <collection property="list属性名称"  javaType="list里面单个泛型的类路径">

    <id property="list里面单个泛型的实体类的id表示字段"  column="对应的表主键"/>

    <result column="表的字段"  property="实体类字段"/>

    。。。。

    </association >

    </resultmap>

  • 相关阅读:
    Elasticsearch (二) 索引
    Elasticsearch (一)搭建与启动
    IDEA 插件
    IDEA 导入华丽的皮肤
    Tomcat https 访问
    oracle系统视图SQL语句整理
    Java内存优化和性能优化的几点建议
    Tomcat配置SSL证书
    sublime集成MinGW,打造C/C++开发环境
    一个简单的Vue.js组件开发示例
  • 原文地址:https://www.cnblogs.com/ln770245726/p/10084095.html
Copyright © 2020-2023  润新知