在MyBatis中,可以使用IN
关键字来将数组参数转换为列表。例如,如果有一个ids
数组作为参数,可以使用以下方式将其转换为MyBatis接受的IN
列表:
<select id="selectByIds" parameterType="java.util.List" resultType="YourResultType">
SELECT * FROM your_table
WHERE id IN
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
List<Integer> idsList = Arrays.asList(ids);
yourMapper.selectByIds(idsList);
这样就可以将数组参数转换为MyBatis接受的IN
列表形式。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:MyBatis参数类型处理策略有哪些