ibatis批量修改、批量增加、批量删除

ibatis批量修改、批量增加、批量删除  

2013-03-06 14:26:48|  分类: 默认分类|字号 订阅

 

 <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>   



 

传入class的list即可

 



 

<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>



 

传入class的list即可

 



 

<delete id="Del" resultMap="Select" parameterClass="list">
      delete      
      from SYS_TABLE
      where id in    
      <iterate conjunction="," open="(" close=")">
        #[]#
      </iterate>
    </delete>



 

传入ID字符串的list即可

 

获取列表跟删除一样,遍历ID的list


 以上都是通过sql执行批量操作,下面是通过java 代码批量插入的例子

public void batchUpdateOrderList(final List<NorTradeDO> list) {  
        getSqlMapClientTemplate().execute(new SqlMapClientCallback() {  
            public Object doInSqlMapClient(SqlMapExecutor sme) throws SQLException {  
                sme.startBatch();  
                for(NorTradeDO norTradeDO : list){  
                    sme.update("TRADE-NOR-UPDATE", norTradeDO);  
                }  
                sme.executeBatch();  
                return null;  
            }  
        });  
    }  

阅读更多
换一批

没有更多推荐了,返回首页