List类型
Mapper.java
public int updateAccount(List<orderjob> orderJobs);</orderjob>
Mapper.xml
<update id="updateAccount" parametertype="com.hongyums.quartz.domain.OrderJob">
update biz_mn_account
set
<trim prefix="ZJE=case " suffix="end,">
<foreach collection="list" item="item">
when dlmc=#{item.dlmc} then #{item.zje}
</foreach>
</trim>
<trim prefix="YQRZJE=case " suffix="end,">
<foreach collection="list" item="item">
when dlmc=#{item.dlmc} then #{item.yqrzje}
</foreach>
</trim>
<trim prefix="YXFJE=case " suffix="end,">
<foreach collection="list" item="item">
when dlmc=#{item.dlmc} then #{item.yxfje}
</foreach>
</trim>
GXSJ=SYSDATE()
where DLMC in
<foreach collection="list" item="item" index="index" open="(" separator="," close=")">
#{item.dlmc}
</foreach>
</update>
如果是Array的话,collerciton=”array”
collerciton=list 和array 是mybaits默认的参数名称,如果你入参中设置了 @Parame
public int updateAccount(@Parame("Param1") List<orderjob> orderJobs);</orderjob>
那么 collerciton=”Param1″
Map类型
Mapper.java
@Data
public class BizMnCreateTableBO {
// 表名称
private String tableName;
// 字段
private Map<string,string> parmes;
}
}</string,string>
Mapper.xml
<update id="createNewTable" parametertype="com.hongyums.system.domain.vo.BizMnCreateTableBO">
CREATE TABLE ${tableName} (
id bigint(20) NOT NULL AUTO_INCREMENT comment '合同模板编号',
dlmc varchar(20) comment '登录名称',
<foreach index="key" item="value" collection="parmes" separator=",">
${key} varchar(50) DEFAULT NULL comment #{value}
</foreach>
, PRIMARY KEY (id))
</update>
我尝试 将${key}改为#{key} 但是发现报错,暂不知原因。
Original: https://www.cnblogs.com/cking98/p/16351178.html
Author: 林间小路
Title: mybatis批量操作
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/620924/
转载文章受原作者版权保护。转载请注明原作者出处!