[英]SpringBoot ignoring my @RequestBody param?
I have the following Controller:我有以下控制器:
@Validated
@RestController
public class ProductController {
@Autowired
private ProductService productService;
@PutMapping("/products/{productId}/costs")
public ResponseEntity<Product> updateProductCost(@RequestHeader String authorization, @PathVariable UUID productId, @RequestBody ProductCost productCost) {
Product updatedProduct = productService.updateProductCost(productId, productCost);
return ResponseEntity.ok(updatedProduct);
}
}
The ProductCost model looks like: ProductCost 模型如下所示:
@Data
@NoArgsConstructor
@Entity
@Table(name = "product_costs", schema = "mws")
public class ProductCost implements Serializable {
private static final long serialVersionUID = 1789128204447938816L;
@Column
private Double unitCost;
@Column
private Double shippingCost;
@Column
private Double pickPack;
@Column
private Double weightHandling;
@Column
private Double handling;
@Column
private Double fbaFee;
@Column
private Double referFee;
@Column
private String currencyCode;
@CreationTimestamp
private Date createdAt;
@UpdateTimestamp
private Date updatedAt;
@Id
@OneToOne
@JoinColumn(name = "product_id")
@JsonBackReference
private Product product;
My problem is that when calling that endpoint, the productCost variable comes with all fields set to null, even though I'm seding it real data.我的问题是,在调用该端点时,productCost 变量的所有字段都设置为 null,即使我正在发送真实数据。
The request body looks like:请求正文如下所示:
{
productCost: {
createdAt: "2020-08-22T21:22:33.989+0000"
currencyCode: "USD"
fbaFee: 0
andling: 0
pickPack: 0
referFee: 0
shippingCost: 0
unitCost: 5
updatedAt: "2020-08-22T21:22:33.989+0000"
weightHandling: 0
}
}
Am I missing something obvious?我错过了一些明显的东西吗? Why is the Product Cost not mapped correctly from my request's
body
to the productCost
variable in the controller?为什么 Product Cost 没有从我的请求
body
正确映射到控制器中的productCost
变量?
Send only value of productCost.仅发送 productCost 的值。
{
createdAt: "2020-08-22T21:22:33.989+0000"
currencyCode: "USD"
fbaFee: 0
andling: 0
pickPack: 0
referFee: 0
shippingCost: 0
unitCost: 5
updatedAt: "2020-08-22T21:22:33.989+0000"
weightHandling: 0
}
Because you are not enclosing productCost in any other class to parse the productCost
key.因为您没有将 productCost 包含在任何其他类中来解析
productCost
键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.