Validation of a list of objects in Spring

后端 未结 12 1265
無奈伤痛
無奈伤痛 2020-11-28 05:30

I have the following controller method:

@RequestMapping(value=\"/map/update\", method=RequestMethod.POST, produces = \"application/json; charset=utf-8\")
@Re         


        
12条回答
  •  悲哀的现实
    2020-11-28 05:39

    @Paul Strack's great solution mixed with Lombok magic:

    @Data
    public class ValidList implements List {
        @Valid
        @Delegate
        private List list = new ArrayList<>();
    }
    

    Usage (swap List for ValidList):

    public ResponseEntityWrapper updateMapTheme(
            @RequestBody @Valid ValidList categories, ...)
    

    (Needs Lombok, but if you don't use it already you really want to try it out)

提交回复
热议问题