![](/img/trans.png)
[英]Spring boot and Angularjs Multipartfile and application/xml
[英]Spring boot - How to validate Multipartfile in rest application
我想驗證 Multipartfile object 的擴展。 我將 @Valid 和我的自定義注釋添加到參數@ImageFileValid
但它不起作用。
@PutMapping("/{id}")
ProductDto updateProduct(@RequestPart @Valid ProductDto product, @PathVariable Long id,@RequestPart @Valid @ImageFileValid MultipartFile image) {
return productMapper.productToProductDto(productService.update(productMapper.productDtoToProduct(product),id));
}
只要類路徑上有 JSR-303 實現(例如 Hibernate 驗證器),Bean Validation 1.1 支持的方法驗證功能就會自動啟用。 這允許 bean 方法在其參數和/或返回值上使用
javax.validation
約束進行注釋。 具有此類注釋方法的目標類需要在類型級別使用@Validated
注釋進行注釋,以便在其方法中搜索內聯約束注釋。
因此,請使用@Validated 注釋(包含) controller @Validated
並報告任何問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.