当前位置:主页 > 查看内容

Mybatis 子查询

发布时间:2021-05-13 00:00| 位朋友查看

简介:子查询 同表中子查询直接在statement中写和sql格式一样 不同表间的子查询通过resultMap来实现 resultMap type Book id BookAndReader autoMapping true id colume id property id/ association property reader javaType Reader autoMapping true select que……

子查询:

同表中子查询直接在statement中写,和sql格式一样;

不同表间的子查询通过resultMap来实现:

<resultMap type = "Book" id = "BookAndReader" autoMapping = "true">
    <id colume = "id" property = "id"/>
    <association property = "reader" javaType = "Reader" autoMapping = "true" select = "queryReaderById" column = "user_id">
        <!--select进行子查询声明,其参数为子查询语句ID-->
        <!--column为子查询参数,即从pojo类传过来的#{id}-->
    </association>
</resultMap>
<select id = "queryReaderAll" resultMap = "BookAndReader">
    select * from tb_order where order_number = #{number}
</select>
<select id = "queryReaderById" resultType = "Reader">
    <!--这里是子查询实体-->
    select * from tb_user where id = #{id}
</select>

这里应该是主查询先执行

;原文链接:https://blog.csdn.net/Kiss_forever/article/details/115496550
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!
上一篇:【MySQL】 库的操作 下一篇:没有了

推荐图文


随机推荐