ibatis2 中iterate 标签使用

对几条数据,根据id号进行批量删除,批量修改是 ibatis2 需要使用 到itrerate 标签,

该标签使用方法如下

 

  <delete id="deleteAccountByList" parameterClass="java.util.List">
    delete from ACCOUNT where ACC_ID in
    <iterate conjunction="," open="(" close=")" >
     #list[]#
    </iterate>
  </delete>
 
 
   <update id="updateAccountList" parameterClass="java.util.List">
    update ACCOUNT set
      ACC_FIRST_NAME = 'gjp'
    where
      ACC_ID in
       <iterate conjunction="," open="(" close=")" >
     #list[]#
    </iterate>
  </update>

 

调用方法:

  public static void deleteAccountList (List list) throws SQLException {
     sqlMapper.delete("Account.deleteAccountByList", list);
   }
 
  public static void updateAccountList (List id) throws SQLException {
     sqlMapper.update("Account.updateAccountList", id);
   }

 

 

测试:

 
    List<Integer> list = new ArrayList<Integer>();
    list.add(Integer.parseInt("1"));
    list.add(Integer.parseInt("11"));
    SimpleExample.updateAccountList(list);
   
   // SimpleExample.deleteAccountList(list);

 

 

 

 

 

 

你可能感兴趣的:(iterate)