spring jdbcTemplate批量插入数据
Post:2019-12-24 18:16:23
Tags:/
spring
/
Visit:
代码实现:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| long startTime=System.currentTimeMillis(); if(sysRoleVO.getAccessIds()!=null){ List<RoleAccessEntity> roleaccessList=new LinkedList<>(); String batchSql="INSERT INTO `role_access`(role_id,access_id) VALUES (:roleId,:accessId)"; for(Integer accessId:sysRoleVO.getAccessIds()){ RoleAccessEntity roleAccessEntity=new RoleAccessEntity(sysRoleVO.getId(),accessId); roleaccessList.add(roleAccessEntity); } SqlParameterSource[] beanSources= SqlParameterSourceUtils.createBatch(roleaccessList.toArray()); namedParameterJdbcTemplate.batchUpdate(batchSql,beanSources); long endTime=System.currentTimeMillis(); log.info("耗时:{}",endTime-startTime); return true; }
|
参考地址: https://www.jb51.net/article/138725.htm