ibatis 批量处理
2010-11-09 21:44
190 查看
最近有些利用ibatis的批量处理的东西。
例如批量插入:
public int inserFSDLBatch(final List<Fsdl> list) throws Exception {
this.getSqlMapClientTemplate().execute( new SqlMapClientCallback(){
public Object doInSqlMapClient(SqlMapExecutor executor)
throws SQLException {
executor.startBatch();
for (Fsdl fsdl : list) {
executor.insert("insertFSDL", fsdl);
}
executor.executeBatch();
return null;
}
});
return Constants.CODE_DAO_SUCCESS;
}
例如批量删除,在网上找了下现在写下来:
1 直接进行自己拼字符串进行传值(在sql中留个占位符一样)
在映射文件中,按如下方法配置:
<delete id="batchDelete" parameterClass="java.lang.String">
delete from tablename where id in ($ids$)
</delete>
因为是用美元符号进行处理,ibatis直接放进去不进行处理,这样我们就可以按照“,”进行连接起来,
ibatis直接组装成sql语句就好了。
2 用iterate
比如<delete id="deleteByIds" parameterClass="java.util.List">
delete from tablename where
<iterate conjunction="," open="id in (" close=")">
#[]#
</iterate>
</delete>
3 对ibatis中对于批量处理的
public Object doInSqlMapClient(SqlMapExecutor executor)
throws SQLException {
// 开始批处理
executor.startBatch();
int num = 1;
for (Object tObject : memberList) {
// 插入操作
executor.update(statement, tObject);
num ++;
if(num %rows == 0)
executor.executeBatch();
}
// 执行批处理
executor.executeBatch();
return Constants.CODE_DAO_SUCCESS;
}
---------rows 设置成500或其他
例如批量插入:
public int inserFSDLBatch(final List<Fsdl> list) throws Exception {
this.getSqlMapClientTemplate().execute( new SqlMapClientCallback(){
public Object doInSqlMapClient(SqlMapExecutor executor)
throws SQLException {
executor.startBatch();
for (Fsdl fsdl : list) {
executor.insert("insertFSDL", fsdl);
}
executor.executeBatch();
return null;
}
});
return Constants.CODE_DAO_SUCCESS;
}
例如批量删除,在网上找了下现在写下来:
1 直接进行自己拼字符串进行传值(在sql中留个占位符一样)
在映射文件中,按如下方法配置:
<delete id="batchDelete" parameterClass="java.lang.String">
delete from tablename where id in ($ids$)
</delete>
因为是用美元符号进行处理,ibatis直接放进去不进行处理,这样我们就可以按照“,”进行连接起来,
ibatis直接组装成sql语句就好了。
2 用iterate
比如<delete id="deleteByIds" parameterClass="java.util.List">
delete from tablename where
<iterate conjunction="," open="id in (" close=")">
#[]#
</iterate>
</delete>
3 对ibatis中对于批量处理的
public Object doInSqlMapClient(SqlMapExecutor executor)
throws SQLException {
// 开始批处理
executor.startBatch();
int num = 1;
for (Object tObject : memberList) {
// 插入操作
executor.update(statement, tObject);
num ++;
if(num %rows == 0)
executor.executeBatch();
}
// 执行批处理
executor.executeBatch();
return Constants.CODE_DAO_SUCCESS;
}
---------rows 设置成500或其他
相关文章推荐
- Ibatis的批量处理-iterateiterate标签
- [Java][ibatis]ibatis批量处理+多表关联查询
- ibatis批量处理+多表关联查询
- ibatis批量处理插入实例
- ibatis 批量处理
- spring ibatis 批量处理数据
- ibatis批量处理+多表关联查询
- ibatis的批量处理
- ibatis批量处理+多表关联查询
- Ibatis批量处理
- ibatis的批量处理
- ibatis配合spring 数据批量处理
- Ibatis的批量处理-iterateiterate标签
- IBatis批量处理那些事
- linux下用Imagemagick批量处理图片
- ibatis学习笔记(一)>>>>>>>sqlMapConfig.xml文件详解
- [Java][ibatis]通过resultMap与resultClass取得Map结果集的差异
- 一步一步使用ibatis (一)
- Spring提供的iBatis的SqlMap配置
- iBatis指南、Hibernate指南、Spring开发指南