这里直接粘贴代码,注意使用的是select标签,下面是批量查询操作
<select id="findByIds" parameterType="java.util.List" resultType="com.jwkj.tt.api.quality.pojo.entity.base.SysDict">
select
id,
dict_info dictInfo,
dict_category dictCategory,
created,
state,
extension
from sys_dict where
id in
<foreach item="id" index="index" collection="list"
open="(" separator="," close=")">
#{id}
</foreach>
</select>
这里是批量增加的操作(一般使用mybatisplus的entity内置的方法)
<select id="batchInsertion" parameterType="java.util.List">
INSERT INTO product_process_drawback
(created,
drawback_id,
information,
company_id,
dept_id,
receiver,
master,
attachment,
state
)
VALUES
<foreach collection="list" index="index" item="item" separator=",">
(#{item.created},
#{item.drawbackId},
#{item.information},
#{item.companyId},
#{item.deptId},
#{item.receiver},
#{item.master},
#{item.attachment},
#{item.state}
)
</foreach>
</select>
这里是批量插入的操作,使用的是select标签,注意foreach标签的使用是批量操作的关键
下面的代码实现批量修改的操作,具体代码如下:
<update id="updateStates" parameterType="java.util.List">
update product_plan set state =
<foreach collection="list" item="item" index="index"
separator=" " open="case ID" close="end">
when #{item.id} then #{item.state}
</foreach>
where id in
<foreach collection="list" index="index" item="item"
separator="," open="(" close=")">
#{item.id,jdbcType=BIGINT}
</foreach>
</update>
一般使用批量修改使用update 方法,不过是知道具体多少条数据,不过执行上来说,会先删除原来的数据再新增,但是使用insert into的方法是实现批量修改,不会删除原来的数据,不过推荐使用上面的方法,能够节省性能