1. 程式人生 > >myBatis解決同時傳遞一個整數和一個Set的問題

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屬性直接獲取到相應的值。