Java开发笔记15(树的列表查询)

1. Controller:

/**
* 通过id查询树列表
* @param id
*/
@GetMapping("/listById")
private Result listByParentId(String id) {
String stationTelecode = getStation(getUser()).getStationTelecode();
List<StationInfRelaTree> treeList = stationInfRelaService.listByParentId(id, stationTelecode);
HashMap<String, List<StationInfRelaTree>> treeMap = new HashMap<>();
treeMap.put("content",treeList);
return Result.ok(treeList);
}

 

2. Service:

List<StationInfRelaTree> listByParentId(String id, String stationTelecode);

 

3. Impl:

@Override
public List<StationInfRelaTree> listByParentId(String id, String stationTelecode) {
List<StationInfRelaTree> resultList = null;
if ("".equals(id) || id == null) {
resultList = stationInfRelaTreeDao.treeAllList(stationTelecode);
if (resultList.size() > 0) {
StationInfRelaTree stationInfRelaTree = resultList.get(0);
Set<StationInfRelaTree> children = stationInfRelaTree.getChildren();
resultList = new ArrayList<>(children);
clearChildren(resultList);
}
return resultList;
}
String val = "-1";
StationInfRelTree findById = InfRelTreeDao.findNoteById(id, stationTelecode);
if (val.equals(findById.getParentId()) || StringUtils.isEmpty(findById.getParentId())) {
resultList = stationInfRelaTreeDao.treeAllList(stationTelecode);
clearChildren(resultList);
} else {
resultList = stationInfRelaTreeDao.treeList(findById.getRelaTreeId(), stationTelecode);
clearChildren(resultList);
}
return resultList;
}

//树的列表展示清除子节点方法
private List<StationInfRelaTree> clearChildren(List<StationInfRelaTree> resultList) {
for (StationInfRelaTree collects : resultList) {
if (collects.getChildren() != null && !collects.getChildren().isEmpty()) {
collects.getChildren().clear();
}
}
return resultList;
}
 

4. Dao:

@Query("select t from StationInfRelaTree t where t.parent = '1' and t.stationCode = :stationCode")
List<StationInfRelaTree> treeAllList(@Param("stationCode") String stationTelecode);
 
@Query("select t from StationInfRelTree t where t.id = :id and t.stationCode = :stationCode")
StationInfRelTree findNoteById(@Param("id") String id, @Param("stationCode") String stationTelecode);
 
@Query("select t from StationInfRelaTree t where t.parent = '1' and t.stationCode = :stationCode")
List<StationInfRelaTree> treeAllList(@Param("stationCode") String stationTelecode);
 
@Query(value = "select * from b_stationinfrelatree t where t.parent_id = :relaTreeId and t.station_code = :stationCode", nativeQuery = true)
List<StationInfRelaTree> treeList(@Param("relaTreeId") String relaTreeId, @Param("stationCode") String stationTelecode);

 

posted @   sensen~||^_^|||&  阅读(84)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
历史上的今天:
2022-04-18 idea2022 破解博客
2022-04-18 对数据库中某字段的数据进行截取
2022-04-18 idea总是弹出svn账户密码框 & Server SSL certificate verification failed
点击右上角即可分享
微信分享提示