前言:由于业务功能特殊性,不需要传递变量来循环select,故将collection属性的值写为静态值来循环即可!
mybatis的xml代码如下:
<select id="qryIAccountHisListIotOld" resultType="com.ai.boss.busi.khzx.common.model.IAccountEntity"
parameterType="java.util.Map">
select *
from (
<foreach collection="{'0101','0102','0103','0104','0105','0106','0107','0108','0109','0110'}" item="item"
separator=" union all ">
select
ACCT_ID,ACCT_NAME,ACCT_TYPE,CREDIT_CLASS,CREDIT,ACCT_VALUE,CUST_ID,ORG_ID,REGION_CODE,COUNTY_CODE,BEGIN_DATE,VALID_DATE,
EXPIRE_DATE,SID,SO_NBR,REMARK,MAIN_SERV_ID,PAY_TYPE from ${tableName}${item} where ACCT_ID in
(#{acctId}) AND
valid_date <![CDATA[ < ]]> to_date(#{expireDate},'yyyy-mm-dd hh24:mi:ss') and expire_date>
to_date(#{validDate},'yyyy-mm-dd hh24:mi:ss')
</foreach>
)
order by expire_date, ACCT_ID, SID
</select>
其中
collection="{'0101','0102','0103','0104','0105','0106','0107','0108','0109','0110'}"即为需要循环的静态值