zoukankan      html  css  js  c++  java
  • MyBatis(3.2.3)

    ResultMaps are used to map the SQL SELECT statement's results to JavaBeans properties. We can define ResultMaps and reference this resultMap query from
    several SELECT statements.

    We can extend one <resultMap> query from another <resultMap> query, thereby inheriting the column to do property mappings from the one that is being extended.

    <resultMap type="Student" id="StudentResult">
        <id property="studId" column="stud_id"/>
        <result property="name" column="name"/>
        <result property="email" column="email"/>
        <result property="phone" column="phone"/>
    </resultMap>
    
    <resultMap type="Student" id="StudentWithAddressResult" extends="StudentResult">
        <result property="address.addrId" column="addr_id"/>
        <result property="address.street" column="street"/>
        <result property="address.city" column="city"/>
        <result property="address.state" column="state"/>
        <result property="address.zip" column="zip"/>
        <result property="address.country" column="country"/>
    </resultMap>

    The resultMap query with the ID StudentWithAddressResult extends the resultMap with the ID StudentResult.

    Now you can use StudentResult resultMap if you want to map only the Student data as shown in the following code:

    <select id="findStudentById" parameterType="int" resultMap="StudentResult">
        SELECT * FROM STUDENTS WHERE STUD_ID=#{studId}
    </select>

    If you want to map the query results with Student along with the Address data, you can use resultMap with the ID StudentWithAddressResult as follows:

    <select id="selectStudentWithAddress" parameterType="int" resultMap="StudentWithAddressResult">
        SELECT STUD_ID, NAME, EMAIL, PHONE, A.ADDR_ID, STREET, CITY, STATE, ZIP, COUNTRY
        FROM STUDENTS S LEFT OUTER JOIN ADDRESSES A 
        ON S.ADDR_ID = A.ADDR_ID
        WHERE STUD_ID = #{studId}
    </select>
  • 相关阅读:
    (转)Linux系统调用和库函数调用的区别
    一个“梦想实践重度障碍者”的思考
    按字节输出数据
    内存区划分、内存分配、常量存储区、堆、栈、自由存储区、全局区[C++][内存管理]
    VimdiffVIM的比较和合并工具
    [每天进步一点 流水账]回顾总结
    计算机就业方向
    ofstream和ifstream详细用法(转)
    ECMAScript 运算符关系运算符
    ECMAScript 语句标签语句
  • 原文地址:https://www.cnblogs.com/huey/p/5230204.html
Copyright © 2011-2022 走看看