JSR-303 Type Checking Before Binding

前端 未结 1 2021
孤独总比滥情好
孤独总比滥情好 2020-12-05 08:39

model....

@Digits(integer=5, fraction=0, message=\"The value must be numeric and less than five digits\")
private int value;

beans file....

相关标签:
1条回答
  • 2020-12-05 09:09

    As you mentioned, you need a user-friendly message in messages.properties. You can use one of the following message codes (with different levels of selectivity):

    • typeMismatch.section.value
    • typeMismatch.value
    • typeMismatch.int
    • typeMismatch

    Also, when you don't know message code, you can simply print the BindingResult - its toString() returns the full description of the binding errors.

    0 讨论(0)
提交回复
热议问题