Reputation: 101
I'm currently using angularJS as my front end, and I'm passing in REST calls to spring MVC to delete multiple objects
In my angular function, I have a method that will return "localhost:9000/api/departments/deleteSelectedDepartments/1517,1518"
deleteSelectedDepartments(selectedDepartments: any): Observable<ResponseWrapper> {
var id = "";
var index = 0;
for(const key in selectedDepartments) {
if(index == (Object.keys(selectedDepartments).length - 1)) {
id += key;
} else {
id += key;
id += ",";
}
index++;
}
return this.http.delete(`${this.resourceDeleteDepartmentsUrl}/${id}`);
}
1517 and 1518 represents the department IDs.
However, I"m receiving errors in my Spring MVC and I'm not entirely sure how to properly receive the object.
Currently in my DepartmentResource.java (spring mvc)
@DeleteMapping("/departments/deleteSelectedDepartments/{ids}")
@Timed
public ResponseEntity<Void> deleteSelectedDepartments(@PathVariable String ids) {
log.debug("REST request to delete Department : {}", ids);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, "blank")).build();
}
The error message I'm getting is error 404 not found.
DELETE http://localhost:9000/api/departments/deleteSelectedDepartments/1589,1590 404 (Not Found)
If there is a better way to go about doing things, please advise! Thank you!
Upvotes: 0
Views: 139
Reputation: 691635
Your mapping is wrong. What you have there is not a request param (the URL would then be /api/departments/deleteSelectedDepartments?departmentIds=1517,1518
).
What you have there is a path variable:
@DeleteMapping("/departments/deleteSelectedDepartments/{departmentIds}")
@Timed
public ResponseEntity<Void> deleteSelectedDepartments(@PathVariable String departmentIds) {
Upvotes: 1