select count(*) from eco_inspect_info
<where>
<if test="sqlParam!=null and sqlParam!=''">and stcd in
<foreach item="stcd" index="index" collection="sqlParam" open="(" separator="," close=")">
#{stcd}
</foreach>
</if>
</where>
红色部分为数据集合,其中sqlParam为数组 或者map,item为循环遍历的值,与#{}里面一致
dao里的请求方法为
List<EcoInspectInfo> findByEcoInspect(@Param("sqlParam") String[] sqlParam);
本文通过一个具体的MyBatis动态SQL示例,详细解释了如何使用<if>和<foreach>标签来构建复杂的SQL查询语句,特别是在处理数组或集合参数时的技巧。
3483

被折叠的 条评论
为什么被折叠?



