MyBatis 使用数组作为参数,这里藏着一个大坑

踩坑记:在传递List<Integer> typeIds作为参数时, foreach不能获取到参数,使用Integer[] typeIds就可以了。

主要代码:

1、接口

<!-- 获取站点列表 -->
List<Station> getList(@Param("typeIds") Integer[] typeIds);

2、xml文件

<select id="getList" resultType="Station">
    select id, `name`, lon, lat, city, county, town, is_native isNative, type, `describe`
    from stations
    where is_native in <foreach collection="typeIds" item="id" open="(" close=")" separator=",">#{id}</foreach>
</select>

 

路漫漫其修远兮,吾将上下而求索

译文:在追寻真理方面,前方的道路还很漫长,但我将百折不挠,不遗余力地去追求和探索。

 

如果您有什么好的想法与方法,欢迎在评论区留言,我们一起讨论~

胜象大百科