[英]Not able to perform edit operation using angular 6 and spring boot
Actually i want to perform the Edit operation in the form.I am passing the Id to the Spring boot Api i have made using angular 6 in forntend but I am getting the error as: 实际上我想在表单中执行Edit操作。我将Id传递给我在forntend中使用angular 6制作的Spring boot Api,但出现以下错误:
The main code to call update method: 调用更新方法的主要代码:
{
this.selectService.updatenewSelection(this.selection.selectionId,0).subscribe((selection)=>{
console.log(selection);
this.router.navigate(['/add-selection']);
},(error)=>{
console.log(error);
});
}
Now the update method in selection.service.ts is 现在,selection.service.ts中的更新方法是
updatenewSelection(id: number, value: any): Observable<Object> {
return this.http.put(`${this.baseUrl}/${id}`, value);
}
The api i have made to update in spring boot is:I have tried both method but it is not still working. 我在Spring Boot中进行更新的api是:我尝试了两种方法,但仍无法正常工作。
@PutMapping("/selections/{id}")
public ResponseEntity<Selection> updateSelection(@PathVariable("id") long id, @RequestBody Selection selection) {
System.out.println("Update Selection with ID = " + id + "...");
Optional<Selection> selectionData = repository.findById(id);
if (selectionData.isPresent()) {
Selection _selection = selectionData.get();
_selection.setSelectionDate(selection.getSelectionDate());
_selection.setSelectedBy(selection.getSelectedBy());
return new ResponseEntity<>(repository.save(_selection), HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
@PutMapping("/selections/update")
public Selection updatenewSelection(@RequestBody Selection selection) {
return repository.save(selection);
}
I get error when clicked the save button is where the "1" is the Id it is passing: 单击保存按钮时,出现错误,即“ 1”是传递的ID:
PUT http://localhost:8080/api/selections/1 400
HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: "OK", url: "http://localhost:8080/api/selections/1", ok: false, …}
error: {timestamp: "2018-10-09T07:29:16.628+0000", status: 400, error: "Bad Request", message: "JSON parse error: Cannot construct instance of `co…ource: (PushbackInputStream); line: 1, column: 1]", path: "/api/selections/1"}
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
message: "Http failure response for http://localhost:8080/api/selections/1: 400 OK"
name: "HttpErrorResponse"
ok: false
status: 400
statusText: "OK"
url: "http://localhost:8080/api/selections/1"
__proto__: HttpResponseBase
您正在发送0
作为值,但是该服务需要Selection
对象!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.