标签:finally get 批量插入 red for back pen ssi family
首先,创建一个简单的 insert 语句:
<insert id=”insertname”>
insert into names (name) values (#{value})
</insert>
然后在 java 代码中像下面这样执行批处理插入:
list < string > names = new arraylist();
names.add(“fred”);
names.add(“barney”);
names.add(“betty”);
names.add(“wilma”);
// 注意这里 executortype.batch
sqlsession sqlsession =
sqlsessionfactory.opensession(executortype.batch);
try {
namemapper mapper = sqlsession.getmapper(namemapper.class);
for (string name: names) {
mapper.insertname(name);
}
sqlsession.commit();
} catch (Exception e) {
e.printStackTrace();
sqlSession.rollback();
第 39 页 共 485 页throw e;
}
finally {
sqlsession.close();
标签:finally get 批量插入 red for back pen ssi family
原文地址:https://www.cnblogs.com/programb/p/12687009.html