zoukankan      html  css  js  c++  java
  • 嵌套映射

    当关联查询非常复杂时,可以用嵌套的select,其原理是在映射复杂数据时执行另一个select来完成

    <resultMap id="order_resultMap2" type="Order" autoMapping="true"> <id column="id" property="id"/> <!-- 指定嵌套查询 column是传给内层查询的参数 --> <association property="user" column="user_id" select="selectUserByUid" javaType="user"/> </resultMap> <!-- 外层查询--> <select id="selectOrderByID2" parameterType="int" resultMap="order_resultMap2"> select * from orders where id = #{id} </select> <!-- 嵌套查询--> <select id="selectUserByUid" parameterType="int" resultType="user"> select *from kuser where id = #{id} </select>

    这种方式同样适用于一对多的关联关系

    <!--自定义映射--> <resultMap id="user_resultMap2" type="user" autoMapping="true"> <result column="username" property="name"/> <collection property="orders" ofType="order" select="selectOrderByUserID" column="id"> <id column="id" property="id"/> </collection> </resultMap> <select id="selectUserByID2" parameterType="int" resultMap="user_resultMap2"> select * from kuser where id = #{uid} </select> <select id="selectOrderByUserID" resultType="order" parameterType="int"> select *from orders where user_id = #{uid} </select>

    1|0

  • 相关阅读:
    HTTP content-type
    python3学习--安装OCR识别库tesserocr
    http post get 类库 httphelper
    MD5
    解决python3中cv2读取中文路径的问题
    web api获得Post数据为空的解决办法
    python3项目打包成exe可执行程序
    pip install 使用国内镜像
    win10家庭版组策略安装
    在国企的日子(第七章 转正)
  • 原文地址:https://www.cnblogs.com/huaobin/p/14162741.html
Copyright © 2011-2022 走看看