码迷,mamicode.com
首页 > 其他好文 > 详细

ibatis使用经验总结

时间:2014-10-30 15:32:22      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:java ibatis sql

1)下面的代码实现ibatis批量保存的功能

public void saveAttachmentOwnerInfo(final List<AttachmentOwnerDTO> attachmentOwnerList,

            final String idAttachmentOwner, final String applyPolicyNo) {

        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("saveAttachmentOwnerInfo", attachOwnerDTO);

                        count++;

                        if (count == 50) {

                            sme.executeBatch();

                            count = 0;

                        }

                    }

                    sme.executeBatch();

                    return null;

                }

            });


        } catch (DataAccessException e) {

           

        }


    }


本文出自 “小李广之博客” 博客,请务必保留此出处http://6817977.blog.51cto.com/6807977/1569627

ibatis使用经验总结

标签:java ibatis sql

原文地址:http://6817977.blog.51cto.com/6807977/1569627

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!