Home>

Validation check when submitted on the screen side in Spring Boot

public class testBean {
    @Digits (integer = 4, fraction = 3)
    BigDecimal bigDecimalValue;
    Integer Ifraction;
}
* Omitted getter setter


When there is a form like the above,

public class testBean {
    @Digits (integer = 4, fraction = Ifraction)
    BigDecimal bigDecimalValue;
    Integer Ifraction;
}

Is it possible to make it variable in this way, for example?

I don't want to do with set from property or custom annotation, so
If it is impossible, I think that I will return with bindingresult after receiving it with Controller.

  • Answer # 1

    I'm sorry just pasting the reference URL, but it seems that the annotation itself can be changed dynamically.
    https://rationaleemotions.wordpress.com/2016/05/27/changing-annotation-values-at-runtime/
    https://qiita.com/hideki/items/bf7684d8d9dbd0bf2aff

    It seems easier to create a custom validator to achieve this.