Mybatis批处理(批量查询,更新,插入)

mybatis批量查询


mapper.java

List<UBaseMenu> findMenuName(List<String> valueList);

mapper.xml

<select id="findMenuName"  resultType="java.lang.String" parameterType="java.util.List">
  	select menu_name
  	from menu
  	where menu_id in
  	<foreach collection="list" item="valueList"  open="(" close=")" separator=",">
  		#{valueList}
  	</foreach>
 </select>

批量插入

mapper.java


int addResource(List<Resource> ResourceList);
mapper.xml

<insert id="addResource" parameterType="java.util.List">
  	 insert into resource (object_id, res_id, res_detail_value, 
      res_detail_name)
      values
    	 <foreach collection="list" item=" ResourceList " index="index" separator=",">
    		  (#{ResourceList.objectId,jdbcType=VARCHAR},
    		   #{ResourceList.resId,jdbcType=VARCHAR},
    		   #{ResourceList.resDetailValue,jdbcType=VARCHAR},
    		    #{ResourceList.resDetailName,jdbcType=VARCHAR}
    		   )
    	 </foreach>
  </insert>

批量更新

mapper.java

int updateRoles(List<String> roleList);
mapper.xml

<update id="updateRoles" parameterType="java.util.List">
  	update role
  	set enabled = '0'
  	where role_id in <foreach collection="list" item="roleIds" index="index"  open="(" separator="," close=")">     
        #{roleIds} 
      </foreach>
  </update>




阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭