<insert id="add">
insert into t_watch_log
<!-- 添加表字段 -->
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="CustomerId != null and CustomerId !=''">CustomerId,</if>
<if test="watch_code != null and watch_code !=''">watch_code,</if>
</trim>
<!-- 注入控制层字段 -->
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="CustomerId != null and CustomerId !=''">#{CustomerId},</if>
<if test="watch_code != null and watch_code !=''">#{watch_code},</if>
</trim>
</insert>
1、根据主键进行新增操作。传入List集合,如果主键重复,则为更新操作。不重复,则是新增操作
<insert id="updateOilList" parameterType="Oil" >
insert into oilno(sinopec_code,content,density)
VALUES
<foreach collection="oilList" item="list" separator=",">
(#{list.sinopec_code},#{list.content},#{list.density})
</foreach>
ON DUPLICATE KEY UPDATE sinopec_code=VALUES(sinopec_code),content=VALUES(content),density=VALUES(density)
</insert>
2、更新批量操作
<update id="updateOilList" parameterType="java.util.List">
<foreach collection="oilList" item="item" index="index" separator=";">
update oilno
<set >
<if test="item.density != null" >
density = #{item.density},
</if>
<if test="item.listprice != null" >
listprice = #{item.listprice},
</if>
</set>
where oilclass = #{item.oilclass}
</foreach>
</update>
3、删除批量操作
<delete id="deleteBatch" parameterType ="java.util.List">
DELETE FROM im_base_account WHERE id in(
<foreach item="o" collection="list" open="" separator="," close="" >
#{o.accountId}
</foreach>
)
</delete>