Mybatis按条件进行批量更新update


where条件中id值不同,更新的good_shelves_name 字段值也不同
一、Mapper.xml
 
id="updateByGoodId" parameterType="com.baiducar.entity.goodsshelves.StorageGoodListDto">

    update base_goods_shelves
    prefix="set" suffixOverrides=",">
        prefix="good_shelves_name =case" suffix="end,">
            collection="listGoods" item="item" index="index">
                when id=#{item.id} then #{item.goodShelvesName}
            
        
        prefix="is_del =case" suffix="end,">
            collection="listGoods" item="item" index="index">
                when id=#{item.id} then #{item.isDel}
            
        
    
    where id in
    collection="listGoods" index="index" item="item" separator="," open="(" close=")">
        #{item.id,jdbcType=BIGINT}
    



二、接口Mapper.java
/**
 * 根据货架id修改货架名称和isdel
 * @param listDto
 * @return
 */
int updateByGoodId(StorageGoodListDto listDto);
三、传输数据dto, StorageGoodListDto.java 和 GoodsShelves.java
public class StorageGoodListDto implements Serializable {

    private static final long serialVersionUID = 8527410449380915629L;
    /**
     * 仓库id
     */

    private Long storageId;

    /**
     * 仓库编号
     */
    private String deposCode;
    /**
     * 仓库名称
     */
    private String deposName;
    /**
     * 仓库地址
     */

    private String deposAddress;
    /**
     * 仓库管理员
     */
    private String deposManager;

    private List listGoods;

省略set和get方法
}

GoodsShelves.java类:

public class GoodsShelves extends BaseEntity {
    private Long id;

    //仓库id
    private Long baseStorageId;
    //货架名称
    private String goodShelvesName;

省略set和get方法
}


你可能感兴趣的:(JAVA,EE)