babyfish-ct/jimmer

[fr]关于dto与Hibernate Validator的结合

sunshio opened this issue · 1 comments

Hibernate Validator是为pojo设计的,无法很好地处理unloaded,我发现了 org.hibernate.validator.engine.HibernateValidatorEnhancedBean这个接口:

Hibernate Validator specific marker interface. Beans implementing this interface would use corresponding $$_hibernateValidator_getFieldValue(String) and $$_hibernateValidator_getGetterValue(String) methods to retrieve bean property values instead of using reflection or any other means.
It is important to keep in mind that in case of explicit implementation of this interface access to all possible constrained getters and fields should be provided, for a class implementing the interface and all its super classes as well. Otherwise unexpected IllegalArgumentException could be thrown by the Hibernate Validator engine.
Since:
6.1
Author:
Marko Bekhta

Hibernate Validator特定的标记接口。实现该接口的bean将使用相应的$$_hibernateValidator_getFieldValue(String)和$$_hibenateValidator_getGetterValue(String)方法来检索bean属性值,而不是使用反射或任何其他方式。
重要的是要记住,在显式实现该接口的情况下,应该为实现该接口及其所有超类的类提供对所有可能的受约束getter和字段的访问。否则,Hibernate Validator引擎可能引发意外的IllegalArgumentException。
自从
6.1
著者
Marko Bekhta

希望dto能实现该接口,处理校验下的unloaded,并提高校验性能(非反射)

image

Try 0.8.131, this is only generated for input with dynamic fields.

  • Set the apt/ksp argument jimmer.dto.hibernateValidatorEnhancement to true
  • Add the dependency about hibernate validation by yourself