Java 介面返回格式封裝
阿新 • • 發佈:2022-04-22
初始是這樣的:
@PostMapping("/parentId")
public Result listByParentId(@RequestBody Map<String,String> map) {
String regionId = map.get("regionId");
//獲取使用者有許可權檢視的車站ID集合
Set<String> stationIds = this.getStationIds();
List<String> ids = new ArrayList<>(stationIds);
return Result.ok(stationRegionTreeService.listByParent(regionId, ids));
}
返回的資料的格式為:
{
"data": [
{
"id": "734",
"relaTreeId": "734",
"parent": "1",
}
]
}
修改後:
@GetMapping("/parentId")
public Result listByParentId(String regionId) {
Set<String> stationIds = this.getStationIds();
List<String> ids = new ArrayList<>(stationIds);
List<StationRegionTree> stationRegionTrees = stationRegionTreeService.listByParent(regionId, ids);
HashMap<Object, List<StationRegionTree>> map = new HashMap<>();
map.put("content",stationRegionTrees);
return Result.ok(map);
}
{
"data": {
"content": [
{
"id": "734",
"relaTreeId": "734",
"parent": "1",
}