How the springmvc @ Validated annotation turns on validation in service

problem description

  1. the server receives the json from the client in controller
  2. controller generates different request objects based on the type field in json, and calls the corresponding service to process it.
  3. before service processes request, the parameters should be determined first, and then the subsequent processing should be carried out.

normally, the request field should be verified directly in the controller, but my controller can only generate a specific request object based on the type field received in the json, so it can only be verified in the service. But the @ Validated object in the service method doesn"t seem to work. The field in
clipboard.png
request has @ NotBlank (message= "xxx") annotations, but it doesn"t work.

< hr >

what is the problem? Or the @ Validated annotation can only be used in controller?

Sep.16,2021

Spring validation validation framework for nested validation of input entities must add @ Valid instead of @ Validated to the corresponding attribute (field)

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4906f-44ced.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4906f-44ced.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?