Validation of a list of objects in Spring

后端 未结 12 1268
無奈伤痛
無奈伤痛 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:55

    I would suggest to wrap your List categories into some DTO bean and validate it. Beside of working validation you will benefit from more flexible API.

    @RequestMapping(value="/map/update", method=RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public ResponseEntityWrapper updateMapTheme(
        HttpServletRequest request, 
        @RequestBody @Valid TagRequest tagRequest,
        HttpServletResponse response
        ) throws ResourceNotFoundException, AuthorizationException {
    ...
    }
    
    public static class TagRequest {
        @Valid
        List categories;    
        // Gettes setters
    }
    

提交回复
热议问题