parameterClass="java.util.List"时请注意

本文介绍了一种使用动态 SQL 拼接的方法来实现 IN 语句中 ID 的动态传递。通过判断变量是否为空以及使用迭代标签来完成 ID 数组的遍历并形成正确的 SQL 语法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

不要在里面带上prepend

<isNotEmpty>
		AND  ID IN
         <iterate close=")" open="(" conjunction=",">#alarmIds[]#</iterate> 
	</isNotEmpty>
 
<?xml version="1.0" encoding="UTF-8"?> <!-- author:hekesong --> <sqlMap> <!-- 查询作物种植信息列表 --> <select id="queryAreaCrops4List" parameterClass="commonj.sdo.DataObject" resultClass="commonj.sdo.DataObject" > select t.*,p.basename,c.cropsname,c.varieties,c.growthcycle,c.recoverycycle,gh.housename,ga.areaname,(case t.status when 1 then '种植中' else '已完成' end) as status_flag from zhnl_area_crops t LEFT JOIN zhnl_productionbase p on t.baseid = p.id LEFT JOIN zhnl_crops c on t.cropsid = c.id LEFT JOIN zhnl_greenhouse gh on t.greenhouseid = gh.id LEFT JOIN zhnl_greenhouse_area ga on t.areasid = ga.id where 1=1 <isNotNull prepend="and" property="basename"> p.basename like '%$basename$%' </isNotNull> <isNotNull prepend="and" property="housename"> gh.housename like '%$housename$%' </isNotNull> <isNotNull prepend="and" property="areaname"> ga.areaname like '%$areaname$%' </isNotNull> <isNotNull prepend="and" property="batchcode"> t.batchcode like '%$batchcode$%' </isNotNull> <isNotNull prepend="and" property="manageScope"> t.greenhouseid in ($manageScope$) </isNotNull> order by t.createtime desc </select> <!-- 根据种植区域id获取种植信息 --> <select id="queryAreaCropsByAreaId" parameterClass="commonj.sdo.DataObject" resultClass="commonj.sdo.DataObject" > select t.*,c.cropsname,c.varieties from zhnl_area_crops t LEFT JOIN zhnl_crops c on t.cropsid = c.id where 1=1 and t.areasid= #areasid# and t.status = '1' </select> <!-- 根据种植批次更新种植信息状态--> <update id="updateStatusByBatchcode" parameterClass="commonj.sdo.DataObject" > update zhnl_area_crops t set t.status = #status# where t.batchcode=#batchcode# </update> <update id="updateStateByBatchcode" parameterClass="commonj.sdo.DataObject" > update zhnl_area_crops t set t.state = #state# where t.batchcode=#batchcode# </update> <select id="getCpfjBycppc" parameterClass="map" resultClass="com.nl.Intelligentag.platform.area_xg.ZhnlAreaCropsCpfj"> select * from zhnl_area_crops_cpfj where batchcode=#cppc# </select> <select id="getCropsBycppc" parameterClass="map" resultClass="com.nl.Intelligentag.platform.productionbase.ZhnlAreaCrops"> select * from zhnl_area_crops where batchcode=#cppc# </select> </sqlMap>
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值