I have a 2 method: first one create product:
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> create(@Validated ProductDTO productDTO){
productService.addProduct(productDTO);
return new ResponseEntity<>("Maxsulot ro'yhatga qo'shildi", HttpStatus.OK);
}
another one update product:
@RequestMapping(method = RequestMethod.PUT)
public ResponseEntity<?> update(@Validated ProductDTO productDTO){
productService.update(productDTO);
return new ResponseEntity<>("Maxsulot ma'lumotlari yangilandi", HttpStatus.OK);
}
Now, I am surprized that, if I sent same data post method works fine(screen1), but put(screen2) method return validation error.
screen1(post)
What the problem is? MyDTO class:
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
}