String ids = StringUtils.join(whiteCategIds,",");
RowMapper<Category> rowMapper = new BeanPropertyRowMapper<>(Category.class);
System.out.println("ids=>"+ids);
String sql = "SELECT CATEG_ID, CATEG_NAME, LEVEL,PARENT_ID FROM CATEGORY WHERE CATEG_ID IN (?)";
List<Category> listCatetory = jdbcTemplate.query(sql,new Object[]{ids},rowMapper);
这个里面ids,使用逗号拼接起来的字符串.比如: 293,14339,1281,11700
如果像上面这样设置参数的话,就仅仅只会只把293 这一个数字设置到占位符里,不要疏忽地以为是把293,14339,1281,11700这4个数字设置到占位符里了.
解决方案 有说用 NamedParameterJdbcTemplate的,后面有时间看一下.
目前的解决方案只能是拼接了.