【发布时间】:2018-02-20 22:25:17
【问题描述】:
我有两种方法: 第一个创建产品:
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> create(@Validated ProductDTO productDTO){
productService.addProduct(productDTO);
return new ResponseEntity<>("Maxsulot ro'yhatga qo'shildi", HttpStatus.OK);
}
另一个更新产品:
@RequestMapping(method = RequestMethod.PUT)
public ResponseEntity<?> update(@Validated ProductDTO productDTO){
productService.update(productDTO);
return new ResponseEntity<>("Maxsulot ma'lumotlari yangilandi", HttpStatus.OK);
}
现在,我很惊讶,如果我发送相同的数据 post 方法工作正常(screen1),但 put(screen2) 方法返回验证错误。 屏幕1(帖子)
问题是什么? MyDTO 类:
public class ProductDTO {
private Long id;
private MultipartFile file;
@NotNull
@Size(min = 2, max = 50)
private String productName;
@NotNull
private Long productPrice;
private String productInfo;
@NotNull
private Long categoryId;
private String unitOfMeasurement;
// getters and setters
}
【问题讨论】:
-
什么是魔法,伙计? :)
-
您能将您的应用程序写入控制台的内容发布出来吗?您可以看到有一些 BindException,从这条消息中您可能能够确定它来自哪里。
-
你能分享你的DTO对象的代码吗?你有任何 initBinders 吗?
-
我添加了 Mydto 类
-
你在使用 Spring Boot 吗?如果不确定,请确保将
HttpPutFormContentFilter添加到您的过滤器列表中。
标签: spring rest post spring-boot put