Servlet如下
/**批量添加
* @param pd
* @throws Exception
*/
public void batch_save(List<PageData> pdList)throws Exception{
dao.save("CapitalMapper.batch_save", pdList);
}
xml文件如下
<!--将所有信息插入表里面,传入参数为list,通过<foreach>来遍历list-->
<insert id="batch_save" parameterType="java.util.ArrayList" useGeneratedKeys="false" >
insert into
<include refid="tableName"></include>
("LOGIN_USER",
"BJ_NUM",
"EXPLAIN",
"BJ_TIME",
"CAPITAL_ID")
SELECT A.* FROM(
<foreach collection="list" item="item" index="index" separator="union all">
(
SELECT
#{item.LOGIN_USER},
#{item.BJ_NUM},
#{item.EXPLAIN},
#{item.BJ_TIME},
#{item.CAPITAL_ID}
FROM DUAL
)
</foreach>
)A
</insert>