gpt4 book ai didi

java - 如何使用新模型/ child 更新/放置对象属性 Webflux Spring Reactive

转载 作者:行者123 更新时间:2023-12-02 01:36:01 25 4
gpt4 key购买 nike

我有一个模型(医院),其属性为(程序)。当我第一次使用仅包含姓名、联系人等的 POST 创建医院时,我想在不同的 PUT 请求中更新 procedure 属性。

我尝试调用 setProcedure setter ,但当我这样做时,我不断在医院对象的程序属性中获取它,

"procedure": {
"scanAvailable": true,
"prefetch": -1
}

// it should be like so i.e example
"procedure": {
"name": "xray",
"price": 1.0,
"hosp_id": 111..,
"id" : 222...
}

我首先创建(POST)创建医院,然后通过推送或设置过程属性中的过程通量来更新(PUT)。

{
"name": "Mercy Hospital",
"address": "3663 S Miami Ave",
"phone": "305-854-4400",
"zipcode": "33133",
"city": "Miami",
"state": "FL",
"lat": 25.7400049,
"lng": -80.21352600000002,
"procedure": {
"scanAvailable": true, <---- the response i'm getting
"prefetch": -1
},
"id": "5d539346e440ed05dfd0fe8a"
}

就像我提到的,我创建了两个模型,每个模型都有一个构造函数以及 getter 和 setter。

医院

@Document // Identifies this class as domain object to be persisted to mongodb
public class Hospital {


private String name;
private String address;
private String phone;
private String zipcode;
private String city;
private String state;
private double lat;
private double lng;
private List<Procedure> procedure;

@Id
private String id;

//
public Hospital() {
}

public Hospital(String name, String address, String phone, String zipcode, String city, String state, double lat, double lng) throws InterruptedException, ApiException, IOException {
this.name = name;
this.phone = phone;
this.address = address;
this.city = city;
this.state = state;
this.zipcode = zipcode;
this.lat = lng;
this.lng = lng;
}

// All the Getters and Setters

程序

@Document
public class Procedure {
private String name;
private double price;
private String hosp_id;
@Id
private String id;

public Procedure() {
}

public Procedure(String name, double price, String hosp_id) {
this.name = name;
this.price = price;
this.hosp_id = hosp_id;
}

// all the Getters and setters Here

}

Controller :


@RestController // Controller and ResponseBody Annotations together
@RequestMapping("/hospitals/v1/hosp/") // Create a base string that the endpoint is built upon
@CrossOrigin // For DEV Angular and Spring app locally REMOVE FOR PRODUCTION
public class HospitalController {
private final HospitalService hospitalService;

@Autowired
public HospitalController(HospitalService hospitalService) {
this.hospitalService = hospitalService;
}

@GetMapping(path = "{id}", produces =
MediaType.APPLICATION_JSON_UTF8_VALUE)
public Mono<Hospital> getHospital(@PathVariable String id) {
return hospitalService.getHospital(id);
}

@PutMapping(path = "{hosp_id}/services", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Mono<Hospital> createService(@RequestBody List<Procedure> procedureMono, @PathVariable String hosp_id) {
return hospitalService.createService(procedureMono, hosp_id);
}

服务

public Mono<Hospital> getHospital(String id) {
return reactiveMongoOperations.findById(id, Hospital.class);
}

public Mono<Hospital> createService(List<Procedure> procedureMono, String hosp_id) {
return getHospital(hosp_id).doOnNext(hospital -> hospital.setProcedure(procedureMono));
}

最佳答案

您收到此消息是因为您正在尝试序列化/反序列化 FluxMono

您无法返回

public class Hospital {
private Flux<Procedure> procedure;
}

您只能序列化/反序列化具体类型

public class Hospital {
private List<Procedure> procedure;
}

由于您还没有发布完整的 Controller ,我无法完全理解您想要做什么,但您无法序列化/反序列化 Monos 或 Fluxes。

关于java - 如何使用新模型/ child 更新/放置对象属性 Webflux Spring Reactive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57518591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com