1. 程式人生 > 其它 >SpringBoot GetMapping和postMaping介面傳值

SpringBoot GetMapping和postMaping介面傳值

(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);
}

介面請求示例:/parentId?regionId=



(2)
@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));
}

介面請求示例:
{
  "regionId" : ""
}
 


(3)
@PostMapping("/deleteTree/{id}")
public Result delate(@PathVariable("id") long id){
try{
stationRegionTreeService.delateTree(id);
return Result.ok();
}catch (Exception e) {
e.printStackTrace();
return Result.error(e);
}
}
介面請求示例:/deleteTree/24
注意:deleteTree後面不能傳空值,否則報404