我在ibatis中使用以下查询来迭代列表。我想添加一个条件,因为列表是空的。在这种情况下,我想在xml:
中更改condition.PFB查询 <statement id="getSearchLateJob" parameterClass="map" resultMap="getCurrentJob_r">
select a.JOBSET as "JOBSET",
a.JOB as "JOB",
a.JOB_NO as "JOB_NO",
a.QUALIFIER as "QUALIFIER",
case when year(a.START_TIME) = 1900 then null else a.START_TIME end as "EXPECTED_START_TIME",
case when year(a.END_TIME) = 1900 then null else a.END_TIME end as "END_TIME",
datediff(mi,a.START_TIME,a.END_TIME) as "DURATION",
b.JOB_AVG as "JOB_AVG",
a.STATUS as "STATUS"
from CA_JOB_STATUS a,JOB_AVG b
where a.JOBSET = b.JOBSET
and a.JOB=b.JOB
and a.JOBSET like #jobSet:VARCHAR#
and a.JOB like #job:VARCHAR#
<!-- and a.STATUS in -->
<dynamic prepend="and a.STATUS in ">
<iterate property= "currentJobStatusArr" open="(" close=")" conjunction=",">
#currentJobStatusArr[]:VARCHAR#
</iterate>
</dynamic>
order by a.END_TIME desc, a.START_TIME desc
在这种情况下,我如何更改迭代列表并构建IN查询的动态前置,以及类似的查询:这样的事情:
更改自:
select * from table where status in (?,?)
要:
select * from table where status like ?
答案 0 :(得分:0)
我找到了解决方案:
<dynamic prepend="and a.STATUS ">
<isNotEmpty property="currentJobStatusArr">
<iterate property= "currentJobStatusArr" open="in (" close=")" conjunction=",">
#currentJobStatusArr[]:VARCHAR#
</iterate>
</isNotEmpty>
<isEmpty property="currentJobStatusArr" >
like #allRec:VARCHAR#
</isEmpty>
</dynamic>