问题描述:用mybatis时,有时不注意容易将sql写错,比如传参为:@Param("updateObjectIds") List<String> updateObjectIds
int deleteByUpdateObjectIds(
@Param("groupId") String groupId,
@Param("updateObjectIds") List<String> updateObjectIds
);
对应的xml写成:
<delete id="deleteByUpdateObjectIds">
delete from t_item_tag_object
where item_tag_group_id=#{groupId}
<if test="updateObjectIds != null and updateObjectIds != ''">
and id not in
<foreach collection="updateObjectIds" item="objectId"
index="index" open="(" close=")" separator=",">
#{objectId}
</foreach>
</if>
</delete>
就会报错:
原因很简单,我们传的是List,那对应的判断应该用size>0,而非!='':
所以改一下这里就可以:
记录开发中的小问题,更多沟通与交流,可以关注我公号: