我的数据库中有一列值,是数组,要使用IdList去查询,因为是按照IDList查询的,所以会有多个数组被查出来,我要对这些数组进行合并并且去重,
我的mapper.xml中的SQL是这么写的
select content from result
<where> id in <foreach collection="array" item="id" index="index" open="(" close=")" separator=",">
#{id} </foreach> <where>
Mapper中是这样的
List<Result> queryResultData(@Param("aray") String[] resultIdList);
controller层是这样的
public ResponseResult<List<Result>> queryResultData(@ApiParam(value = "IDList", required true) @RequestParam(value="resultIdList")String[] resultIdList){
List<Result> result = resultService.queryResultData(resultIdList);
return ResponseResult.SUCCESS(result);
}
ServiceImpl是这样写的
这是我查询content数组的语句
public List<Result> queryResultIdList(String[] resultIdList){
List<Result> result = resultMapper.queryResutData(resultIdLIst);
for(int i = 0; i < result.size(); i++) {
}
}
这是我写的数组合并去重的语句
Map<String, Object> nodes = new HashMap();
List<Map<String,Object>> nodeList = new ArrayList();
nodes.forEach((k,v)->{
if(v!=null && v instanceof Map){
nodeList.add((Map)v);
}
});
Map<String, Object> edges = new HashMap();
List<Map<String,Object>> edgeList = new ArrayList();
edges.forEach((k,v)->{
if(v!=null && v instanceof Map){
edgeList.add((Map)v);
}
});
List<Map<String,Object>> nodeList1 = nodeList.stream().collect(Collectors,collectingAndThen)(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> Long.parseLong(o.get("_id")+"")))), ArrayList::new);
List<Map<String,Object>> edgeList1 = edgeList.stream().collect(Collectors,collectingAndThen)(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> Long.parseLong(o.get("_id")+"")))), ArrayList::new);
但是这么写的话就会出现返回值的时候,就会变成
nodes.put("nodes",nodesList1);
edges.put("edge",edgeList1);
这样
主要问题是,我的搜索怎么和我的数组合并的代码,能顺利的走下来,就是下面的数组怎么接上上面查询的值,
还有后面的返回值的问题,求各位大佬讲解,这种代码我第一次写