---
title: "spring+ibatis的批量提交"
author: "wengsibo"
date: "2010-12-29T16:25:13Z"
tags: []
categories: ["企业架构"]
slug: "spring-ibatis"
draft: false
lastmod: "2010-12-29T16:25:13Z"
id: 854987
url: "https://wengsb.iteye.com/blog/854987"
---

```java
public int addSendMsg(final Msg msg) {
		this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
			public Object doInSqlMapClient(SqlMapExecutor executor)
					throws SQLException {
				executor.startBatch();
				int batch = 0;
				String[] tel_nbrs = msg.getTel_nbrs().split(",");
				if(tel_nbrs.length <= 0)return 0;
				for (int i = 0; i < tel_nbrs.length; i++) {
					// 参数1为：ibatis中需要执行的语句的id
					String content = msg.getContent();
					msg.setTel_nbr(tel_nbrs[i]);
					executor.insert("msg-info.sendMsg", msg);
				}
				executor.executeBatch();	//提交
				return 1;
			}
		});
		return 1;
	}

```