简体   繁体   中英

Spring Validation with applyIf attribute in Annotations

I've tried to set applyIf attribute on spring annotation with some custom exspression. As exampe I have a form:

class MyForm {

    @NotBlank
    private String name;
    @NotNull
    @MinSize(applyIf = "name not equals myValue", value = 1) 
    private List<String> addresses;
    ...
}

But when I try to validate form above spring perceives myValue from exspression as property. The it tries to find getters setters for it.

Also, I've tried to dig org.springmodules.validation.valang.parser.ValangParser , but unfortunatly java docs are not present for this class.

I can't find any examples with this stuff(Only really simple cases like: " name is not blank "). Will be good if you suggest some usefull documentation. Or correct my exspression for correct verifying my goals.

As in comment under the question, the syntax should be "name NOT EQUALS 'myValue'"

http://www.springbyexample.org/maven/site/sbe-validation/0.92/apidocs/org/springmodules/validation/valang/ValangValidator.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM