Ibatis结合Spring的使用

来源:互联网 发布:合同法总论 知乎 编辑:程序博客网 时间:2024/04/29 20:19

Ibatis结合Spring的使用:大致按下面6步


1:首先根据表,建一个序列化的实体类


2:MVN:引入ibatis相关的jar包


3:主的ibatis的配置文件


4:每个SqlMap的配置文件


5:spring的application-context.xml加上主的配置ibatis的配置文件


6:事务处理的实现类


7: 批量操作:


public void batchAddStockNewProduct(final List<StockNewProduct> productList) {
execute(new SqlMapClientCallback<Object>() {


@Override
public Object doInSqlMapClient(SqlMapExecutor executor)
throws SQLException {executor.startBatch(); // 一定要有,通知开始批量
int batch = 0;


for (StockNewProduct stockNewProduct : productList) {


executor.insert("StockNewProduct.add", stockNewProduct);


// 每10条批量提交一次。
if (batch == 10) {


executor.executeBatch();


batch = 0;
}
      }

      executor.executeBatch(); // 不足10条记录


return null;
}
});
}


0 0
原创粉丝点击