关联查询:
一对一:
1、业务扩展类
    核心:用resultType指定的类的属性包含多表查询的所有字段。
2、resultMap
    通过添加属性成员建立两个类之间的连接
<!--利用resultMap实现一对一  -->
    <select id="queryPersonsByReOnetoOne" parameterType="int" resultMap="person-card-map">
        select p.*,c.* from person p inner join personcard c
        on p.cardid=c.cardid
        where p.id=#{id}
    </select>
    
    <!-- resultMap实现映射 -->
    <resultMap type="person" id="person-card-map">
        <!-- person信息 -->
        <id property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="age" column="age"/>
        <!--一对一时,对象成员使用assocation实现映射,javaType指定该属性的类型  -->
        <association property="card" javaType="PersonCard">
            <id property="cardid" column="cardid"/>
            <result property="cardinfo" column="cardinfo"/>
        </association>
    </resultMap>
 
一对多:
<!--一对多关联查询  -->
    <select id="queryClassAndPersons" parameterType="int" resultMap="class-person-map">
        select c.*,p.* from person p
        inner join class c
        on c.classid=p.classid
        where c.classid=#{classid}
    </select>
    
    <!-- 类和表的对应关系 -->
    <resultMap type="class" id="class-person-map">
        <!-- 先配class -->
        <id property="classid" column="classid" />
        <result  property="classname" column="classname" />
        <!-- 配置成员属性。属性类型:jdbcType;属性的元素类型:ofType -->
        <collection property="persons" ofType="Person">
            <id property="id" column="id"/>
            <result property="name" column="name"/>
            <result property="age" column="age"/>
        </collection>
    </resultMap>
   

最新文章

  1. hdu-acm steps Common Subsequence
  2. iOS自定义的UISwitch按钮
  3. poj 3020 Antenna Placement (最小路径覆盖)
  4. JavaScript之获取和设置元素属性
  5. 一些常用的Intent及intent-filter的信息
  6. 【转】Zookeeper-Watcher机制与异步调用原理
  7. C#语言之“String.Split”的使用【转】
  8. android 5.0 -- 主题
  9. Gluon炼丹(Kaggle 120种狗分类,迁移学习加双模型融合)
  10. 常用linux命令备忘
  11. Android--操作图片Exif信息
  12. UE4 Notes
  13. bzoj 2599: [IOI2011]Race (点分治 本地过了就是过了.jpg)
  14. Eclipse导入项目时出错提示 project is missing required library
  15. Eclipse + PyDev 快捷键
  16. Hive基础之Hive的存储类型
  17. JavaScript 对象属性作实参以及实参对象的callee属性
  18. Linux下调整根目录的空间大小
  19. CodeForces - 999C
  20. C++中函数调用时的三种参数传递方式详解

热门文章

  1. H3C网络监测工具命令
  2. CMD操纵Mysql命令大全
  3. Visioi形状相关应用
  4. 第四阶段:2.从零打造一款工具APP产品
  5. 第二阶段:2.商业需求分析及BRD:7.商业需求文档3
  6. 为什么IIS应用程序池回收时间默认被设置为1740分钟?
  7. codeforces -1214 E
  8. 【他山之石】mysql编码问题总结
  9. 20191031-7 beta week 1/2 Scrum立会报告+燃尽图 05
  10. 基于 HTML5 WebGL 与 WebVR 3D 虚实现实的可视化培训系统