I am reading a tutotral regarding the REST Resource Naming...
http://api.example.com/device-management/managed-devices/{id}/scripts/{id}:clone
This is an example of a best practice in the naming, but I don't know how to declare it using the @PathVariable
annotation and distinguish one {id}
from {id}:clone
public ResponseEntity<?> clone (
HttpServletRequest request,
@PathVariable long id, ...) {
..
}
答案 0 :(得分:0)
您需要通过变量名称或来自value
的属性@PathVariable
来区分这两个ID,例如:
@GetMapping("http://api.example.com/device-management/managed-devices/{idManagedDevice}/scripts/{idScript}"
public ResponseEntity<?> clone (HttpServletRequest request,
@PathVariable long idManagedDevice,
@PathVariable long idScript,
) {
..
}
或者:
@GetMapping("http://api.example.com/device-management/managed-devices/{id}/scripts/{idScript}"
public ResponseEntity<?> clone (HttpServletRequest request,
@PathVariable(value="id") long idOfManagedDevice,
@PathVariable(value="idScript") long idOfScript,
) {
..
}