You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "kaiser20106 (via GitHub)" <gi...@apache.org> on 2025/07/23 18:26:47 UTC

Re: [I] 请问如何全局配置 jvalidationNew ? [dubbo]

kaiser20106 commented on issue #15339:
URL: https://github.com/apache/dubbo/issues/15339#issuecomment-3109671239

   下面是我个人根据代码和文档汇总结果
   ```
   dubbo:
     # 参数校验
     consumer:
       validation: true
     provider:
       validation: true
   ```
   ```
   //实体类
   public class GoodEntity {
   
       @Null(groups = GoodService.InsertSelective.class, message = "新增时id必须为空")
       private Integer id;
   }
   
   //服务
   public interface GoodService {
   
       
       @interface InsertSelective {} //与方法同名接口,首字母大写,用于区分验证场景,如:@NotNull(groups = GoodService.InsertSelective.class),可选
       ResponseEntity<Integer> insertSelective(@RequestBody GoodEntity goodEntity);
   
       
   }
   ```
   > "message": "Failed to validate service: org.example.cloud.dubbo.GoodService , method: insertSelective, cause: [ConstraintViolationImpl{interpolatedMessage='新增时id必须为空', propertyPath=id, rootBeanClass=class org.example.cloud.entity.GoodEntity , messageTemplate='新增时id必须为空'}]",
   
   
   注意是**与方法同名接口**
   而不是插入方法用 `@interface Save {} `
   
   
   [参考用例](https://github.com/apache/dubbo-samples/tree/master/dubbo-samples-validation)
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org