myBatis解决同时传递一个整数和一个Set的问题

代码如下:

List<Item> getItemByNames(@Param("collection") Set<String> names, @Param("type") Integer type);

注意使用了Param注解

在mapper文件中

<select id="getItemByNames" resultMap="BaseResultMap">
  	select id,name from item 
    where name in
  	<foreach collection="collection" open="(" close = ")" item = "item" index = "index" separator=",">
        #{item}
    </foreach>
    and type = #{type}
</select>

可以直接通过param属性直接获取到相应的值。

猜你喜欢

转载自blog.csdn.net/qq_19734597/article/details/82777051