当要对两个或者多个表进行联查的时候,此方法比较繁杂,不建议使用
//将数组转换成list集合 List<String> cliniids = Arrays.asList(paramMap.get("ids").split(",")); //提取unitmapEntityList集合中的部分数据 List<String> unitCodeList = unitmapEntityList.stream().collect(Collectors.mapping(TableEntity::getUnitcode, Collectors.toList())); List<TabletEntity> eresultlist = commonApiDao.getScrollData(TableEntity.class, " itemCode=?0 and clinicItemCode=?1 and unitcode in (?2) and cfgcomplete=0 ", new Object[]{paraMap.get("itemCode"), paraMap.get("clinicItemCode"), unitCodeList}, new LinkedHashMap<>()).getResultlist(); //常用查询 TabletEntity tabletEntity= commonApiDao.find(TabletEntity.class,param.get("id")); //注意:条件参数从0开始【?0】,否则报错 commonApiDao.batchInsert(eresultlist); commonApiDao.batchUpdate(eresultlist); //注意:将eresultlist中的集合数据批量操作方式一:
//需要先载入数据库的连接驱动,如果第一次启动项目的时候npJdbcTemplate=null,则重启项目即可 @Autowired NamedParameterJdbcTemplate npJdbcTemplate; //编写sql,配置参数,执行 String deleteSql=" delete from table where itemCode=:itemCode and unitcode in (:unitcode)"; HashMap<String, Object> paramMap = new HashMap<>(); paramMap.put("unitcode",queryForObject); paramMap.put("itemCode",entity.getItemCode()); npJdbcTemplate.update(deleteSql, paramMap);方式二:
//编写sql,配置参数,执行 String[] ids =paramMap.get("id").split(","); String sql="delete from table WHERE id in (:id)"; NamedParameterJdbcTemplate namedParameterJdbcTemplate=new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource());//连接数据库 MapSqlParameterSource argsMap=new MapSqlParameterSource(); argsMap.addValue("id", Arrays.asList(ids)); //参数 namedParameterJdbcTemplate.update(sql, argsMap);