开发者

Is spring Form validation different than JSR bean validation

开发者 https://www.devze.com 2023-02-14 19:21 出处:网络
I have seen that annotation like @NotNull etc are given in JSR Specifications. Now as i am currently studying Spring MVC and building website in that

I have seen that annotation like @NotNull etc are given in JSR Specifications.

Now as i am currently studying Spring MVC and building website in that

so i am confused are they same or different and have they any relation with spring M开发者_如何学CVC.

because for .eg if i use @NotEmpty then will spring knows that if i leave it empty then it displays in form with error message like we code in validator and its messages

This is my method , i am confused were to add @Valid

 public String add(@ModelAttribute("personAttribute") Person person) {
        logger.debug("Received request to add new person");


        personService.add(person);

        // This will resolve to /WEB-INF/jsp/addedpage.jsp
        return "hibernate/addedpage";
    }


Spring form validation is different, but it also support JSR-303 validation. You can validate a whole model attribute by annotating it with @Valid (as a method parameter)

public String add(@Valid @ModelAttribute("personAttribute") Person person) { .. }

You would need:

  • a JSR-303 provider on the classpath
  • <mvc:annotation-driven /> in the spring-mvc xml to enable validation
0

精彩评论

暂无评论...
验证码 换一张
取 消