子查詢:
同表中子查詢直接在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://www.uj5u.com/shujuku/273790.html
標籤:其他
下一篇:MySQL基礎--DDL
