Building Dynamic ConstraintViolation Error Messages

后端 未结 2 756
囚心锁ツ
囚心锁ツ 2021-02-06 03:02

I\'ve written a validation annotation implemented by a custom ConstraintValidator. I also want to generate very specific ConstraintViolation objects th

2条回答
  •  深忆病人
    2021-02-06 03:17

    If you use message codes you can simply add something like {0} in them.

    For example: "The field {0} must not be empty."

    And then use hibernateContext.addMessageParameter("0", fieldName); instead of addExpressionVariable(...).

    That worked for me.

提交回复
热议问题