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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to