我在@RestController类中有以下代码:
@RequestMapping("api/")
@RestController
public class RecommendationsController {
@PostMapping(path = "cart")
public List<RecommendationDTO> getCartRecommendations(@NonNull @RequestBody List<CartItemDTO> cart){
System.out.println(cart);
return null;
}
}
这是我的CartItemDTO类中的代码:
public class CartItemDTO {
private String productId;
private Double quantity;
public CartItemDTO(String productId, Double quantity) {
this.productId = productId;
this.quantity = quantity;
}
public String getProductId() {
return productId;
}
public Double getQuantity(){
return quantity;
}
这是我与邮递员发送的请求:
[
{
"productId": "20000010",
"quantity": 5.0;
},
{
"productId": "20000011",
"quantity": 7.0;
}
]
这是有效的,但是当我像下面那样更改代码时,收到错误的请求:错误的语法
public class CartItemDTO {
private String productId;
public CartItemDTO(String productId) {
this.productId = productId;
}
public String getProductId() {
return productId;
}
}
有要求:
[
{
"productId": "20000010"
},
{
"productId": "20000011"
}
]
有人知道怎么了吗?
您已经删除了;从情况来看?即