我目前正在做一個專案,我需要向 spring 發送一個 POST 請求。我已經尋找了幾個小時的解決方案,但沒有找到可行的解決方案。當我開發那部分時,這個請求奏效了。問題是,在創建一些新功能(另一個控制器中的 2 個新端點)之后,用于創建或更新物體的 POST 請求停止作業,而無需更改特定區域中的代碼。
控制器:
@RestController
@CrossOrigin
@RequestMapping
public class SensorController {
@PostMapping(value = "/createSensor", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<UUID> insertSensor(@RequestBody SensorDto sensorDto){
UUID sensorId = sensorService.createSesor(sensorDto);
return new ResponseEntity<>(sensorId,HttpStatus.CREATED);
}
}
消耗和生產的部分最初不存在,我嘗試了它,因為在其他帖子上看到但沒有幫助這種情況。
SensorDto:
public class SensorDto extends RepresentationModel<SensorDto> {
private UUID id;
private String description;
private Integer maxValue;
private Device device;
來自郵遞員的電話: image
標題:標題
有人可以幫我讓它再次作業嗎?
編輯:從另一個控制器詢問的代碼
@PostMapping("/addSensorToDevice")
public ResponseEntity<UUID> addSensor(@RequestBody DeviceSensorLinkDto deviceSensorLinkDto){
System.out.println("OOO: " deviceSensorLinkDto.toString());
if(deviceService.addSensor(deviceSensorLinkDto)){
return new ResponseEntity<>(deviceSensorLinkDto.getDeviceId(), HttpStatus.OK);
}else {
return new ResponseEntity<>(deviceSensorLinkDto.getDeviceId(), HttpStatus.EXPECTATION_FAILED);
}
}
@PostMapping("/addClientToDevice")
public ResponseEntity<UUID> addClient(@RequestBody DeviceClientLinkDto deviceClientLinkDto){
System.out.println("OOO: " deviceClientLinkDto.toString());
if(deviceService.addClient(deviceClientLinkDto)){
return new ResponseEntity<>(deviceClientLinkDto.getDeviceId(), HttpStatus.OK);
}else {
return new ResponseEntity<>(deviceClientLinkDto.getDeviceId(), HttpStatus.EXPECTATION_FAILED);
}
}
這個作業以及洗掉傳感器物體的請求。
uj5u.com熱心網友回復:
您的應用程式中似乎有多個@JsonBackReferenceand@JsonManagedReference因此,您必須為所有對提供一個名稱,如下所示:
@JsonBackReference(value = "something")
@JsonManagedReference(value = "something")
@JsonBackReference(value = "something-else")
@JsonManagedReference(value = "something-else")
您可以在參考檔案中找到有關此的一些資訊:
參考屬性對的邏輯 have;用于鏈接托管和反向參考。如果只有單個參考對(例如,只有父/子鏈接的節點類,由一個托管參考和匹配的反向參考組成),則可以使用默認名稱。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/369940.html
上一篇:無法通過JPA訪問嵌入式類的屬性
