MyBatis 同时传递一个整数和一个Set参数

90 阅读1分钟

代码如下:

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

注意使用了Param注解

在mapper文件中

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

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