Ibatis批量处理

1.插入

    <insert id="insTable"  resultClass="int">
      INSERT INTO [dbo].[table]
      ([Id]
      ,[FId],[IsDel],[CreateTime]
     )
      VALUES
      <iterate conjunction="," open="" close="">
        (#[].Id#
        ,#[].FId#

        ,0
        ,GETDATE()
       )
      </iterate>
    </insert>

2.读取

    <select id="queryTable" resultMap="Table" parameterClass="List">
      select Id, FId, CreateTime
      from  Table (nolock) where IsDel=1 and [Id] in
      <iterate open="(" close=")" conjunction=",">
        #[]#
      </iterate>
    </select>

3.修改

 <update id="updateTable" parameterClass="list">
       begin
      <iterate conjunction="">
        update TABLE
        set
        Fid=#[].FId#
        where id = #[].Id#;
      </iterate>
      end;
  </update> 
                var tables = new List<Table>()
                {
                    {new Table() {Id = 1, FId = "100"}},
                    {new Table() {Id = 2, FId = "102"}},
                };
                this.mapper.Update("updateTable", tables);

4.删除

<delete id="delTable"  parameterClass="List">
      delete
      from TABLE
      where id in
      <iterate conjunction="," open="(" close=")">
        #[]#
      </iterate>
</delete>
                var ids=new List<int>(){2,3,4};
                this.mapper.Delete("delTable", ids);
时间: 2024-07-31 14:33:06

Ibatis批量处理的相关文章

IBatis批量插入数据

IBatis插入注意,数据量比较多的花,需要分批插入,策略是dao里面控制插入批次,mapper里面批量插入即可 @Override public Long insertBatch(List<WaiterDO> list) throws Exception { //每批次插入数量 int batchCount = 3; //游标 int index = 0; //批次 int batchNum = 1; for(;;){ if(index+batchCount>=list.size())

ibatis批量执行分析

最近做pos数据文件解析及入库的开发,其中pos的流水文件一个文件中就包含8000多条数据,每次插入数据库执行的sql都是相同的.因此考虑到使用批量插入来提升效率.查看ibatis的文档,看到提供了startBatch和executBatch两个方法,看名字大概就知道这两个方法和批量执行有关.我立马在之前的for循环外面加上了这两个方法: sqlMap.getSqlMapClient().startBatch();for (Map<String, Object> map : list) {  

ibatis 批量插入数据

ibatis 和mybatis不太一样,如过不是自己定义的类型(即java自带类型): 传入参数类型的属性是parameterClass,mybatis是parameterType:返回参数类型属性名称为resultClass,mybatis是resultType <insert id="release" parameterClass="java.util.List">      <![CDATA[         insert into     

2007版本excel多个sheet页数据通过ibatis批量导入数据库

页面部分 <form method="post" name ="test" enctype="multipart/form-data"> <input type="file" name="file"/> </form> 实体类部分 public Class Test{ private String id; private String name; private Stri

ibatis 批量插入oracle总结

1. 使用批量插入最先想到如下的插入语句 insert into a (id,name) values('','') ,('','') 但是 oracle 并不支持这种写法 然后查询得知可以使用如下写法 insert all into a(id,name) values('','') into a(id,name) values('','') (注:可以一次插入一个表也可以多个表) 但是这种方式有一种限制,就是 行数乘以列数不能大于1000(我没有验证),而且这种方式据说效率不高(我没有验证)

ibatis批量执行保存操作

1)批量保存只连接数据库一次,性能高效: 对应的保存sql还是和一般的一样的: @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void saveAttachmentOwnerInfo(final List<AttachmentOwnerDTO> attachmentOwnerList, final String idAttachmentOwner, final String

ibatis、hiberate之批量插入

ibatis批量插入 首先dao层要传递一个list过来,比如是一个user(list数据) 接着xml文件中这么配置,注意类型是"java.util.List, <insert id="insert" parameterClass="java.util.List"> insert into user(acount,pwd) <iterate conjunction=","> (#user[].acount#,#

IBatis的SQL批量操作

1.Ibatis批量添加(传入class的list即可) <insert id="Add" resultMap="Select" parameterClass="list"> insert all <iterate conjunction=""> into SYS_TABLE (id,Category,Name,Code,Status) values(#[].Id#,#[].Category#,#[].

ibatis使用经验总结

1)下面的代码实现ibatis批量保存的功能 public void saveAttachmentOwnerInfo(final List<AttachmentOwnerDTO> attachmentOwnerList, final String idAttachmentOwner, final String applyPolicyNo) { try { this._execute(new SqlMapClientCallback() { public Object doInSqlMapCli