标签:ibatis 批量操作
1)批量保存只连接数据库一次,性能高效;
对应的保存sql还是和一般的一样的;
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void saveAttachmentOwnerInfo(final List<AttachmentOwnerDTO> attachmentOwnerList,
final String idAttachmentOwner, final String applyPolicyNo) throws PafaDAOException {
try {
this._execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor sme) throws SQLException {
sme.startBatch();
int count = 0;
for (AttachmentOwnerDTO attachOwnerDTO : attachmentOwnerList) {
attachOwnerDTO.setAttachmentOwnerId(idAttachmentOwner);
attachOwnerDTO.setApplyPolicyNo(applyPolicyNo);
sme.insert("personnelInfo.saveAttachmentOwnerInfo", attachOwnerDTO);
count++;
if (count == 50) {
sme.executeBatch();
count = 0;
}
}
sme.executeBatch();
return null;
}
});
} catch (Exception e) {
java.out.println(JSON.toJSONString(attachmentOwnerList));
}
}
本文出自 “小李广之博客” 博客,请务必保留此出处http://6817977.blog.51cto.com/6807977/1597101
标签:ibatis 批量操作
原文地址:http://6817977.blog.51cto.com/6807977/1597101