zoukankan      html  css  js  c++  java
  • 一对一、一对多的关联查询 ?

    <mapper namespace="com.lcb.mapping.userMapper">

    <!--association 一对一关联查询 -->

    43 页 共 485 页<select id="getClass" parameterType="int"

    resultMap="ClassesResultMap">

    select * from class c,teacher t where c.teacher_id=t.t_id and

    c.c_id=#{id}

    </select>

    <resultMap type="com.lcb.user.Classes" id="ClassesResultMap">

    <!-- 实体类的字段名和数据表的字段名映射 -->

    <id property="id" column="c_id"/>

    <result property="name" column="c_name"/>

    <association property="teacher"

    javaType="com.lcb.user.Teacher">

    <id property="id" column="t_id"/>

    <result property="name" column="t_name"/>

    </association>

    </resultMap>

    <!--collection 一对多关联查询 -->

    <select id="getClass2" parameterType="int"

    resultMap="ClassesResultMap2">

    select * from class c,teacher t,student s where c.teacher_id=t.t_id

    and c.c_id=s.class_id and c.c_id=#{id}

    </select>

    <resultMap type="com.lcb.user.Classes" id="ClassesResultMap2">

    <id property="id" column="c_id"/>

    <result property="name" column="c_name"/>

    <association property="teacher"

    javaType="com.lcb.user.Teacher">

    <id property="id" column="t_id"/>

    <result property="name" column="t_name"/>

    </association>

    <collection property="student"

    ofType="com.lcb.user.Student">

    <id property="id" column="s_id"/>

    <result property="name" column="s_name"/>

    </collection>

    </resultMap>

    </mapper>

  • 相关阅读:
    剑指offer-整数中1出现的次数
    数据流中的中位数
    二叉搜索树的后序遍历序列
    Java 线程阻塞和唤醒
    Java 线程池
    Python哈希表和解析式
    Python线性数据结构
    python 基础知识
    pyenv虚拟环境管理python多版本和软件库
    Paramiko的SSH和SFTP使用
  • 原文地址:https://www.cnblogs.com/programb/p/12687030.html
Copyright © 2011-2022 走看看