Mybatis批量插入写法、批量查询写法

 

 批量插入

<insert id="insertBatchList">
        INSERT INTO tag  (
        `tag_name`,
        `tag_weight`,
        )
        VALUES
        <foreach collection ="list" item="tag" separator =",">
            (#{tag.tagName}, #{tag.tagWeight})
        </foreach >

 

 

批量查询 

(集合方式)

<if test="systemIdList != null and systemIdList.size()>0 ">
                and system_id in
                <foreach item="systemId" collection="systemIdList" open="(" separator="," close=")">
                    #{systemId}
                </foreach>
            </if>

说明:collection="systemIdList"

这里的“systemIdList” 写的是你在mapper.java文件里使用的注解写的@Param   ,如果没有加这个注解,默认的就是 “list”

如果是传的对象,那么这里就是用的属性名称

 

数组方式

 

posted @ 2021-04-27 20:54  yvioo  阅读(139)  评论(0编辑  收藏  举报