将一个用逗号分隔的字符串转为list,代码如下:
//普通拼接方式
String str="aa,aaaa,ddd,ads,sasd";
Type type = new TypeToken<List<String>>() {}.getType();
List<String> list= new Gson().fromJson(str, type);
//java8流式拼接
//1.
//comRecInfoList是对象list filter()中是筛选条件
comRecInfoList.stream().filter(rec -> rec.getOrgid().equals(orgId)).collect(Collectors.toList());
//2.
Object[] objects = list.stream().map(OrgInternal::getId).toArray();
orgId = StringUtils.join(objects, ",");
//mybatis中使用
AND r.orgid in
<foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
#{item}
</foreach>
个人记录常用代码。