Iv'e seen this nice mechanism:
http://www.mkyong.com/spring-mvc/spring-3-mvc-and-jsr303-valid-example/
Is it possible to make the @Valid annotation avaialble for all the Controllers with validation? It seems very redundant to do the following:
@RequestMapping(value = "/getPlayerAccounts", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public QueryResultsDTO<PlayerAccountResultDTO> getPlayerAccounts(@RequestBody **@Valid** FilteredQueryRequestDTO filteredQueryRequestDTO,
**BindingResult result**) {
**this.validateDTO(result);**
return this.playerService.getPlayerAccounts(filteredQueryRequestDTO);
}
Reduandant code:
@Valid
BindingResult result
this.validateDTO(result);
These seems like a recurring pattern, probably someone already solved it? maybe with aspects? I dont care that all my methods and controllers will have the @Valid login, most of the DTOs they recieve will be valid anyway (since no validation annotations are applied to them)
Thanks