Mybatis中如何使用in查询 简单使用教程
😂 这篇文章最后更新于1131天前,您需要注意相关的内容是否还可用。
很简单,例如dao
List<Map> findByYear(List<Integer> yearList,@Param("yearOldList") List<Integer> yearOldList);
xml
<select id="findByYear" resultType="java.util.Map">
SELECT * from my_data where year in
<foreach collection="yearOldList" item="year" index="index" open="(" close=")" separator=",">
#{year}
</foreach>
</select>
item需要和#{}里值一致,在多个参数情况collection与List别名一致,如果是一个参数的话collection默认填list就行。
但是如果多个参数填list的话就会报错
Parameter 'list' not found. Available parameters are [0, yearOldList, param1, param2]
从报错中可以看出collection可以填别名、param1(代表第一个参数)、param2(代表第二个参数),但是还是建议在多参数时用别名
留言评论
暂无留言