springboot+Mybatis批量增删改查(java批量添加、修改带非空判断)
1、批量添加--xml代码
<insert id="insertBatchList" parameterType="java.util.List"> INSERT INTO sw_rs_set_holdstandard ( hold_createtime, hold_flag, company_id, hold_type, train_id, hold_level3, hold_level4 ) values <foreach collection="list" item="item" index="index" separator=","> <trim prefix=" (" suffix=")" suffixOverrides="," > now(),1,#{item.companyIdbs,jdbcType=BIGINT} <if test="item.holdType!=null"> ,#{item.holdType,jdbcType=BIGINT} </if> <if test="item.holdType==null"> ,0 </if> ,#{item.trainIdbs,jdbcType=BIGINT} <if test="item.holdLevel3!=null"> ,#{item.holdLevel3,jdbcType=BIGINT} </if> <if test="item.holdLevel3==null"> ,0 </if> <if test="item.holdLevel4!=null"> ,#{item.holdLevel4,jdbcType=BIGINT} </if> <if test="item.holdLevel4==null"> ,0 </if> </trim> </foreach> </insert>
2、批量添加--调用
/** * 批量添加 */ int insertBatchList(List<SwRsSetHoldstandardEntity> list);
3、批量修改--xml代码
<update id="updateBatchList" parameterType="java.util.List"> UPDATE sw_rs_set_holdstandard <trim prefix="set" suffixOverrides=","> <trim prefix="hold_updatetime =case" suffix="end,"> <foreach collection="list" item="item"> when hold_id = #{item.holdId} then now() </foreach> </trim> <trim prefix="hold_level3 =case" suffix="end,"> <foreach collection="list" item="item" index="index"> <if test="item.holdLevel3!=null"> when hold_id = #{item.holdId} then #{item.holdLevel3} </if> </foreach> </trim> <trim prefix="hold_level4 =case" suffix="end,"> <foreach collection="list" item="item"> <if test="item.holdLevel4!=null"> when hold_id = #{item.holdId} then #{item.holdLevel4} </if> </foreach> </trim> </trim> where hold_id in <foreach collection="list" index="index" item="item" separator="," open="(" close=")"> #{item.holdId} </foreach> </update>
4、批量修改--调用
/** * 批量修改 */ int updateBatchList(List<SwRsSetHoldstandardEntity> list);
5、批量删除--xml
<delete id="deleteByPrimaryKey" parameterType="java.util.List"> delete from description where id in <foreach collection="list" item="id" open="(" separator="," close=")"> #{id} </foreach> </delete>
6、查询xml
<select id="getHoldstandardList" parameterType="com.rxjy.modules.ku.entity.SwRsSetHoldstandardEntity" resultMap="BaseResultMap"> SELECT tp.train_level trainLevel,tp.train_id trainIdbs,tp.train_postname trainPostname,-1 companyIdbs ,case hs.hold_type when 1 then '资源' when 2 then '客源' else '' end holdTypeName ,ifnull(cp.co_name,'集团') coName,hs.* ,<include refid="Base_Column_List"></include> from sw_rs_trainingrepository tp LEFT JOIN sw_rs_set_holdstandard hs on hs.train_id=tp.train_id and hs.hold_flag=1 <if test="companyId!=null"> and hs.company_id=#{companyId} </if> <if test="holdType!=null"> and hs.hold_type=#{holdType} </if> LEFT JOIN sw_bs_company cp on cp.company_id=hs.company_id where tp.train_isenable=1 <if test="trainPostname!=null and trainPostname!=''"> and tp.train_postname=#{trainPostname} </if> order by tp.train_rank asc </select>
当你的才华还撑不起你的野心时,那你就应该静下心来学习;当你的能力还驾驭不了你的目标时,那就应该沉下心来历练!