1.批量更新
sql:
1.1根据多个条件批量更新
<update id="updateStateByPositionIds">
update table set state = #{state} where
(position_id, group_id) in
<foreach collection="relationVos" item="item" separator="," close=")" open="(">
(#{item.positionId}, #{item.groupId})
</foreach>
</update>
mapper:
//多个条件
int updatePushStateByPositionIds(@Param("relationVos")List<PositionAndGroupSo> positionAndGroupSoList,
@Param("state") Byte state);
//单个条件
int updatePushStateByPositionIds(@Param("positions")List<string> positions,
@Param("state") Byte state);
@Data
public class PositionAndGroupRequest implements Serializable {
private static final long serialVersionUID = 7171837841501948123L;
private Integer groupId;
private Integer positionId;
}
1.2单个条件批量更新
<update id="updateStateByPositionIds">
update table set state = #{state} where
position_id in
<foreach collection="positions" item="item" separator="," close=")" open="(">
#{item}
</foreach>
</update>
2.批量查询
mapper:
List<string> selectStateByPositionIdList(@Param("relationVos")List<PositionAndGroupSo> positionAndGroupSoList);
//单个条件
int selectStateByPositionIds(@Param("positions")List<string> positions);
@Data
public class PositionAndGroupRequest implements Serializable {
private static final long serialVersionUID = 7171837841501948123L;
private Integer groupId;
private Integer positionId;
}
2.1 多个条件批量更新
<select id="selectStateByPositionIdList">
select state table where
(position_id, group_id) in
<foreach collection="relationVos" item="item" separator="," close=")" open="(">
(#{item.positionId}, #{item.groupId})
</foreach>
</select>
2.1 单个条件批量更新
<select id="selectStateByPositionIds">
select state table where
(position_id, group_id) in
<foreach collection="positions" item="item" separator="," close=")" open="(">
#{item}
</foreach>
</select>
3.批量插入
mapper:
List<string> insertStateByPositionIdList(@Param("relationVos")List<PositionAndGroupSo> positionAndGroupSoList);
//单个条件
int insertStateByPositionIds(@Param("positions")List<string> positions);
@Data
public class PositionAndGroupRequest implements Serializable {
private static final long serialVersionUID = 7171837841501948123L;
private Integer groupId;
private Integer positionId;
}
3.1 多个条件批量新增
<insert id="insertStateByPositionIdList">
insert into table (position_id, group_id)
values
<foreach collection="relationVos" item="item" separator="," >
(#{item.positionId}, #{item.groupId})
</foreach>
</insert>
3.1 单个条件批量插入
<insert id="insertStateByPositionIds">
insert into table (position_id)
values
<foreach collection="positions" item="item" separator="," close=")" open="(">
#{item}
</foreach>
</insert>