1.新增:--返回值為增加的的行數(shù)
int insertLableBatch(@Param("list")List<UserGroupFilterLabel> list);
SQL語句
<insert id="insertLableBatch" parameterType="com.sf.cps.mana.model.UserGroupFilterLabel">
insert into ti_user_group_filter_label
(emp_group_id,label_type,label_code,label_name,label_symbol,label_content,label_valid,create_name,create_emp,create_time)
values
<foreach collection="list" item="re" separator=",">
(
#{re.empGroupId,jdbcType=INTEGER},
#{re.labelType,jdbcType=VARCHAR},
#{re.labelCode,jdbcType=VARCHAR},
#{re.labelName,jdbcType=VARCHAR},
#{re.labelSymbol,jdbcType=VARCHAR},
#{re.labelContent,jdbcType=VARCHAR},
#{re.labelValid,jdbcType=INTEGER},
#{re.createName,jdbcType=VARCHAR},
#{re.createEmp,jdbcType=VARCHAR},
now()
)
</foreach>
</insert>
2修改:
int updateLableBatch(@Param("list")List<UserGroupFilterLabel> list);
SQL語句
<!--批量修改-跟java循環(huán)其實是一樣的只是邏輯清晰些-->
<update id="updateLableBatch" parameterType="com.sf.cps.mana.model.UserGroupFilterLabel">
<foreach collection="list" separator=";" item="item">
update ti_user_group_filter_label
<set>
<if test="item.empGroupId != null">
emp_group_id = #{item.empGroupId,jdbcType=INTEGER},
</if>
<if test="item.labelType != null">
label_type = #{item.labelType,jdbcType=VARCHAR},
</if>
<if test="item.labelCode != null">
label_code = #{item.labelCode,jdbcType=VARCHAR},
</if>
<if test="item.labelName != null">
label_name = #{item.labelName,jdbcType=VARCHAR},
</if>
<if test="item.labelSymbol != null">
label_symbol = #{item.labelSymbol,jdbcType=VARCHAR},
</if>
<if test="item.labelContent != null">
label_content = #{item.labelContent,jdbcType=VARCHAR},
</if>
<if test="item.labelValid != null">
label_valid = #{item.labelValid,jdbcType=INTEGER},
</if>
<if test="item.modifyEmp != null">
modify_emp = #{item.modifyEmp,jdbcType=VARCHAR},
</if>
<if test="item.modifyName != null">
modify_name = #{item.modifyName,jdbcType=VARCHAR},
</if>
modify_time = now()
</set>
where id = #{item.id,jdbcType=INTEGER}
</foreach>
</update>
3.批量刪除
/**
*
* 方法描述:根據(jù)ids集合進(jìn)行刪除
* @return
*/
int deleteByIds(List<Integer> ids);
二强缘、Mapper.xml動態(tài)sql
collection:傳遞來的參數(shù),可以是list,array(數(shù)組),還可以是map的key赏胚,可以是pojo中的屬性
item:循環(huán)中的當(dāng)前元素
index:當(dāng)前元素的下標(biāo)
open:循環(huán)的開始
close:循環(huán)的結(jié)束
separator:分隔符
<delete id="deleteByIds" parameterType="list">
delete from user where id in
<foreach collection="list" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
這段SQL最終會被自動組合成:delete from user where id in ( ? , ? )