我写了一个角度代码,用于从ag-grid删除多行。我通过向服务器发送请求来删除行。在删除单行时,它工作正常。但是,当我删除多行时,URL更改了(“ /”始终替换为%5C),并且出现HTTP响应错误。谁能帮我解决这个问题?这是我的代码:
DeleteFile.component.ts:
private deletePath = "http://localhost:3028/controller/removeDirectory";
delete(){
if(this.selectedRows.length!=0){
for(let i=0;i<this.selectedRows.length;i++){
this.params = new HttpParams();
this.params = this.params.append('dir', this.selectedRows[i]);
this.http.get(this.deletePath,{params : this.params}).subscribe( (data : any )=> {
});
}
this.http.get(this.path).subscribe( // this code is to set results to an array for display ag-grid
(data: any) => {
this.searchResults = data;
console.log(this.searchResults);
},
error => console.log(error)
);
this.selectedRows = [];
}
else{
alert("no rows selected to delete");
}
}
这是控制器中的方法:
@RequestMapping(value = "/removeDirectory", method = RequestMethod.GET)
public @ResponseBody void removeDirectory(@RequestParam("dir") String dir) {
fileSearchProcessing.removeDirectory(dir);
}
我得到的错误是:对于dir = C:/ Users / Acer / Desktop / Dhana / m
core.js:1633 ERROR HttpErrorResponse {headers: HttpHeaders, status: 500, statusText: "OK", url: "http://localhost:3028/controller/removeDirectory?dir=C:%5CUsers%5CAcer%5CDesktop%5CDhana%5Cm", ok: false, …}