多條件批量查詢語句 (這里是分表匯總成一個表進行查詢,大家用不上多表,直接把多表替換成單表即可,主要看第二個《foreach的內容》)
xml
<select id="getSameCarton" resultType="java.lang.Integer"> select count(1) from ( <foreach collection="qrTableList" item="qrTable" separator=" union all "> select * from ${qrTable} </foreach> ) t where 1=1 and <foreach collection="printQrList" item="qr" separator="or" open="(" close=")"> purchase_order_no=#{qr.purchaseOrderNo} and purchase_order_line_number = #{qr.purchaseOrderLineNumber} and carton =#{qr.carton} </foreach> </select>
mapper.java

serviceImpl.java

補充:printQrList是一個 List<QrPrintTransferCommitVo>

最終效果: 將運行的sql從控制台,粘貼到數據庫工具中運行,可以看到。

補充:
帶 in 的查詢
and wk.workshop_code in ( '' <foreach collection="workshopCodeList" item="item" close="" open="," separator=","> #{item} </foreach> )

