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>

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐