我目前正在使用angularJS作为我的前端,我正在通过REST调用spring MVC来删除多个对象
在我的角度函数中,我有一个将返回的方法 “本地主机:9000 / API /部门/ 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和1518表示部门ID。
但是,我在Spring MVC中收到错误,我不完全确定如何正确接收该对象。
目前在我的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();
}
我收到的错误消息是找不到错误404。
DELETE http://localhost:9000/api/departments/deleteSelectedDepartments/1589,1590 404 (Not Found)
如果有更好的办法,请指教!谢谢!
答案 0 :(得分:1)
您的映射是错误的。你所拥有的不是请求参数(URL将是/api/departments/deleteSelectedDepartments?departmentIds=1517,1518
)。
你有什么路径变量:
@DeleteMapping("/departments/deleteSelectedDepartments/{departmentIds}")
@Timed
public ResponseEntity<Void> deleteSelectedDepartments(@PathVariable String departmentIds) {