Spring Validate group Classification checksum _srping

Source: Internet
Author: User

In using spring validate, my usage is to annotate the checksum on the Bean, as follows:

Wishclip.java:

@NotNull
@Size (max = 512)
Private String URL;

Then use this in spring controller:

Public responseentity<?> addwish (@Valid @RequestBody wishclipdto wish)

But there is a problem, my demand is that the URL in the WISHCLILP is only required in the create when the incoming check, in the update does not need to pass in, such use will be in the Create and update when the URL is validated.

After Google, spring3.1 supports group-level checksums: http://blog.codeleak.pl/2014/08/validation-groups-in-spring-mvc.html and https:// Narmo7.wordpress.com/2014/04/26/how-to-set-up-validation-group-in-springmvc/.

The changes are as follows:

Define two null interfaces in Wishclip, and then use these two interface on the annotations of the URL

/** Validate only when Create **/
public interface createwish{};
/** Validate only when update **/
public interface updatewish{};

And then use it in the controller:

Public responseentity<?> Addwish (@Validated ({createwish.class}) @RequestBody wishclipdto wish)

Public responseentity<void> Update (@Validated ({updatewish.class}) @RequestBody wishclipdto wish)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.