What does the @Valid annotation indicate in Spring?

前端 未结 8 1499
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 20:38

In the following example, the ScriptFile parameter is marked with an @Valid annotation.

What does @Valid annotation do?

<
相关标签:
8条回答
  • 2020-12-04 21:27

    IIRC @Valid isn't a Spring annotation but a JSR-303 annotation (which is the Bean Validation standard). What it does is it basically checks if the data that you send to the method is valid or not (it will validate the scriptFile for you).

    0 讨论(0)
  • 2020-12-04 21:30
    public String create(@Valid @NotNull ScriptFile scriptFile, BindingResult result, ModelMap modelMap) {    
        if (scriptFile == null) throw new IllegalArgumentException("A scriptFile is required");        
    

    I guess this @NotNull annotation is valid therefore if condition is not needed.

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