Java 接口返回格式封装
初始是这样的:
@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",
}

浙公网安备 33010602011771号