String[] panelArr = glass_id.split("\n"); StringBuffer panelSb = new StringBuffer(); for (int i = 0; i < panelArr.length; i++) { panelSb.append("'").append(panelArr[i]).append("',"); } panelSb.deleteCharAt(panelSb.length() - 1); hql.append(" AND column_nameIN (") .append(panelSb.toString()) .append(")");
--------------------------------20190313--------------------------------------------------------
此外使用拉姆达表达式也很简便
List<String> panelIds = ...; String layout; String panels = panelIds.stream() .map(p -> "'" + p.substring(0, p.length() - 2) + "'") .collect(Collectors.joining(", "));