ibatis一次从多个表查询
关键字: ibatis
在分库分表的情况下,我们可以利用在同一个数据源下,ibatis一次从多个表查询并返回结果,xml如下:
<select id="getAll" resultMap="ProductBaseResultMap"> <iterate property="tables" conjunction="union all"> select //查询表字段 from product_base_$tables[]$ where sku_id in <iterate open="(" conjunction="," close=")" property="pks"> #pks[]# </iterate> </iterate> </select> |
ibatis 用in查询 ,实例如下:
<select id="findProductListByProductIds" resultMap="productMap" parameterClass="java.util.HashMap"> select //字段名 from $tableName$ p inner join <iterate open="(" close=")" conjunction="union" property="productIdList"> <![CDATA[select #productIdList[]# as pid ]]> </iterate> <![CDATA[as temp on p.product_id = temp.pid ]]> </select> |
本文固定链接: http://www.chepoo.com/ibatis-a-query-from-multiple-tables.html | IT技术精华网