ibatis标签iterate实现批量处理数据


1.批量插入数据(基于oracle的insert all语法)
<insert id="insert" parameterClass="java.util.List">
insert all
<iterate conjunction=" ">
    into t_table ( key, local, value) values
    (#beans[].name#, #beans[].local#, #beans[].value#)
</iterate>
select * from dual
</insert>

2.批量删除数据
<delete id="delete">
    delete from t_table where
    <iterate conjunction="or" open="(" close=")">
	key = #[]#
    </iterate>
</delete>

其中传进来的参数可以是数组也可以是list
或者
<delete id="delete">
    delete from t_table where key in
    <iterate property="keys" conjunction="," open="(" close=")">
	#keys[]#
    </iterate>
</delete>

或者
<delete id="delete">
    delete from t_table
    <iterate prepend="where" property="keys" conjunction="," open=" key in (" close=")">
	#keys[]#
    </iterate>
</delete>

你可能感兴趣的:(ibatis,批量插入,iterate,批量处理)