ibatis组合Oracle的iterate insert批量插入

ibatis结合Oracle的iterate insert批量插入

ibatis批量插入oracle数据库

<insert id="batchInsert" parameterClass="java.util.List">
	INSERT INTO SYS_ROLE_MENU(
	ROLE_ID,	
	MENU_ID	
		)
	SELECT A.*
	FROM (
		<iterate  conjunction ="union all" >
		SELECT
			#list[].key# as ROLE_ID,
			#list[].value# as MENU_ID
		from dual
		</iterate >
	  ) A
	</insert>

java代码

	   /**
		* 批量插入功能
		*/
	   @SuppressWarnings("unchecked")
	   public void updateBatch(final List<ListKeyValue> list, String roleId) {
		   SqlMapClient sqlMapClientTemplate = baseDao.getSqlMapClient();
		   try {
			   sqlMapClientTemplate.startTransaction();//开启事务
			   /**事务todo start***/
			   /**先执行删除所有**/
			   Map<String,Object> deleteParamMap=new HashMap<>();
			   deleteParamMap.put("id",roleId.split(","));
			   sqlMapClientTemplate.delete("delete",deleteParamMap);
			   sqlMapClientTemplate.insert("batchInsert",list);
			   /**事务todo end***/
			   sqlMapClientTemplate.commitTransaction();//提交事务
		   } catch (SQLException e) {
			   e.printStackTrace();
		   }finally {
			   try {
				   sqlMapClientTemplate.endTransaction();//事务完成
			   } catch (SQLException e) {
				   try {
					   sqlMapClientTemplate.getCurrentConnection().rollback();	//事务回滚
				   } catch (SQLException e1) {
					   e1.printStackTrace();
				   }
				   e.printStackTrace();
			   }
		   }

	   }

欢迎分享,(木庄网络博客交流QQ群:562366239

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论