IBatis批量处理那些事
来源:互联网 发布:2017网络红歌在线试听 编辑:程序博客网 时间:2024/06/08 04:23
IBatis批量处理之Sql样例
批量更新:
<update id="Update" resultMap="Select" parameterClass="list"> begin <iterate conjunction=""> update SYS_TABLE set Category=#[].Category#, Name =#[].Name#, Code =#[].Code#, Status =#[].Status# where id = #[].Id#; </iterate> end; </update>
批量删除:
<delete id="Del" resultMap="Select" parameterClass="list"> delete from SYS_TABLE where id in <iterate conjunction="," open="(" close=")"> #[]# </iterate></delete>
批量插入:
<insert id="Add" resultMap="Select" parameterClass="list"> insert all <iterate conjunction=""> into SYS_TABLE (id,Category,Name,Code,Status) values(#[].Id#,#[].Category#,#[].Name#, #[].Code#,#[].Status#) </iterate> <!--下面这句必须加,不然会提示找不到SELECT--> select * from dual</insert>
注释一定要注意!select * from dual 这句必须加
IBatis批量处理之Java样例
总体思路都一样,一条的执行,批量提交
批量更新
public void batchUpdate( final String statementName, final List list) { try { if (list != null ) { this .getSqlMapClientTemplate().execute( new SqlMapClientCallback() { public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { executor.startBatch(); for ( int i = 0, n = list.size(); i < n; i++) { executor.update(statementName, list.get(i)); } executor.executeBatch(); return null ; } }); } } catch (Exception e) { if ( log .isDebugEnabled()) { e.printStackTrace(); log .debug( "batchUpdate error: id [" + statementName + "], parameterObject [" + list + "]. Cause: " + e.getMessage()); } } }
批量删除
public void batchDelete( final String statementName, final List list) { try { if (list != null ) { this .getSqlMapClientTemplate().execute( new SqlMapClientCallback() { public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { executor.startBatch(); for ( int i = 0, n = list.size(); i < n; i++) { executor.delete(statementName, list.get(i)); } executor.executeBatch(); return null ; } }); } } catch (Exception e) { if ( log .isDebugEnabled()) { e.printStackTrace(); log .debug( "batchDelete error: id [" + statementName + "], parameterObject [" + list + "]. Cause: " + e.getMessage()); } } }
批量插入
public void batchInsert( final String statementName, final List list) { try { if (list != null ) { this .getSqlMapClientTemplate().execute( new SqlMapClientCallback() { public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { executor.startBatch(); for ( int i = 0, n = list.size(); i < n; i++) { executor.insert(statementName, list.get(i)); } executor.executeBatch(); return null ; } }); } } catch (Exception e) { if ( log .isDebugEnabled()) { e.printStackTrace(); log .debug( "batchInsert error: id [" + statementName + "], parameterObject [" + list + "]. Cause: " + e.getMessage()); } } }
Merge into的用法 – 待完善
0 0
- IBatis批量处理那些事
- iBatis batch处理那些事
- iBatis batch处理那些事
- ibatis 批量处理
- ibatis的批量处理
- ibatis批量处理
- ibatis的批量处理
- ibatis 批量处理
- spring ibatis 批量处理数据
- ibatis批量处理插入实例
- ibatis批量处理+多表关联查询
- Ibatis的批量处理-iterateiterate标签
- ibatis配合spring 数据批量处理
- [Java][ibatis]ibatis批量处理+多表关联查询
- ibatis 对事务和批量提交的处理,以及回滚的处理
- ibatis批量操作
- IBATIS 批量更改操作
- Spring+ibatis批量存储
- 浏览器缓存机制
- 问题:设计一个大学教师和学生管理程序, 教师包括 编号、姓名、职称和教研室 数据的输入输出; 大学生包括编号、姓名、性别、班号、英语、高等数学和数据结构三门课程成绩的输入输出和计算平均分; 研究生包
- MySQL学习笔记第10课(共10课)
- sql l连接
- POJ 1013 Counterfeit Dollar 砝码称重
- IBatis批量处理那些事
- 使用mach-smdk6410.c制作内核刷入显示乱码解决方法
- 第六章JSP标准标签库JSTL(1)
- 如何将VS 2015中的项目上传到github
- POJ 1328 Radar Installation 贪心最少区间问题
- connect 端口分配源码分析
- 页面内容超出范围解决方法
- 关于分布式存储
- SSH常用参数