cfg_index_info保存改为批量,dao保存sql不带last_insert_id

This commit is contained in:
wangxin
2018-11-16 11:11:15 +08:00
parent 89253a265d
commit 3603527ec8
3 changed files with 75 additions and 2 deletions

View File

@@ -7,6 +7,9 @@ import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
@@ -44,6 +47,7 @@ import com.nis.web.dao.configuration.StringCfgDao;
import com.nis.web.dao.specific.ConfigGroupInfoDao;
import com.nis.web.security.UserUtils;
import com.nis.web.service.CrudService;
import com.nis.web.service.SpringContextHolder;
/**
* IP相关配置事务类
@@ -108,8 +112,19 @@ public class IpCfgService extends CrudService<IpCfgDao,BaseIpCfg> {
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveCfgIndexOf(List<CfgIndexInfo> cfgIndexInfos){
for (CfgIndexInfo cfgIndexInfo : cfgIndexInfos) {
ipCfgDao.saveCfgIndex(cfgIndexInfo);
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
SqlSession batchSqlSession = null;
try{
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
for(int index = 0; index < cfgIndexInfos.size();index++){
CfgIndexInfo cfgIndexInfo = cfgIndexInfos.get(index);
((IpCfgDao) batchSqlSession.getMapper(IpCfgDao.class)).saveCfgIndex(cfgIndexInfo);
}
batchSqlSession.commit();
}finally {
if(batchSqlSession != null){
batchSqlSession.close();
}
}
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)