新增
<insert id="insert2">
insert into hotel_room_price (product_id, sell_date, price)
values
<foreach collection="list" item="emp" separator=",">
(#{emp.productId,jdbcType=BIGINT},#{emp.sellDate,jdbcType=DATE},#{emp.price,jdbcType=DECIMAL})
</foreach>
</insert>
修改
<update id="update2" parameterType="java.util.List">
update hotel_room_price set
price=
<foreach collection="list" item="item" index="index" separator=" " open="case product_id" close="end">
when #{item.productId,jdbcType=BIGINT} then #{item.price,jdbcType=DECIMAL}
</foreach>
where product_id in
<foreach collection="list" index="index" item="item" separator="," open="(" close=")">
#{item.productId,jdbcType=BIGINT}
</foreach>
and sell_date in
<foreach collection="list" index="index" item="item" separator="," open="(" close=")">
#{item.sellDate,jdbcType=DATE}
</foreach>
</update>
void insert2(@Param("list") List<HotelRoomPrice> list);
int update2(@Param("list")List<HotelRoomPrice> list);
第二种批量修改
<!-- //房价日历-批量修改-->
<update id="update2" parameterType="java.util.List">
update hotel_room_price
<trim prefix="set" suffixOverrides=",">
<trim prefix="price =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.price!=null">
when product_id=#{i.productId} then #{i.price}
</if>
</foreach>
</trim>
<trim prefix="line_price =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.line_price!=null">
when product_id=#{i.productId} then #{i.line_price}
</if>
</foreach>
</trim>
<trim prefix="line_discount =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.line_discount!=null">
when product_id=#{i.productId} then #{i.line_discount}
</if>
</foreach>
</trim>
<trim prefix="calendar_discount =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.calendar_discount!=null">
when product_id=#{i.productId} then #{i.calendar_discount}
</if>
</foreach>
</trim>
</trim>
where product_id in
<foreach collection="list" index="index" item="item" separator="," open="(" close=")">
#{item.productId,jdbcType=BIGINT}
</foreach>
and sell_date in
<foreach collection="list" index="index" item="item" separator="," open="(" close=")">
#{item.sellDate,jdbcType=DATE}
</foreach>
</update>