List<Long> noticeIdList = new ArrayList<>();
noticeIdList.add(1L);
noticeIdList.add(2L);
noticeIdList.add(3L);
List<TbNotice> noticeList = selectNoticeListByList(noticeIdList);
List<TbNotice> noticeList = selectNoticeListByArray(noticeIdList.toArray(new Long[noticeIdList.size()]));
/**
*
*
* @param ids ID数组
* @return 对象集合
*/
public List<Notice> selectNoticeListByArray(Long[] ids);
/**
*
*
* @param noticeIdList ID集合
* @return 对象集合
*/
public List<Notice> selectNoticeListByList(List<Long> noticeIdList);
数组参数: collection 用 array接收参数
<select id="selectNoticeListByArray" parameterType="Long" resultMap="NoticeResult">
select * from notice where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</select>
集合参数: collection 用 list接收参数
<select id="selectNoticeListByList" parameterType="Long" resultMap="NoticeResult">
select * from notice where id in
<foreach item="id" collection="list" open="(" separator="," close=")">
#{id}
</foreach>
</select>
多参数的使用
/**
* @param ids ID数组
* @param keyword 关键字
* @return 对象集合
*/
public List<Notice> selectNoticeListByArray(@Param("ids") Long[] ids,@Param("keyword") String keyword);
数组参数: collection 用 @Param值 ids 接收参数
<select id="selectNoticeListByArray" resultMap="NoticeResult">
select * from notice where id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
and creater_key = #{keyword}
</select>