Spring validation for RequestBody parameters bound to collections in Controller methods

后端 未结 3 604
遇见更好的自我
遇见更好的自我 2020-12-10 16:32

I have

An Entity:

package org.ibp.soq;

public class MyEntity {

    private String field1;
    private String field2;

    //..get         


        
3条回答
  •  春和景丽
    2020-12-10 17:13

    As you might have guessed this cannot be achieved using Spring Validation. Spring Validation implements Bean Validation(JSR 303/349) as opposed to Object validation. Unfortunately a collection is not a Java Bean. You have two options

    • Wrap your list inside a Java Bean
    • Call the validator manually in your bulk create method myEntityValidator. validate(targetObject, errors).

提交回复
热议问题