Home > Back-end > Spring - how to modify RequestParam required parameters in the web of the default validation behavio
Spring - how to modify RequestParam required parameters in the web of the default validation behavio
Time:12-01
Currently springboot project parameters validation is not empty to use @ RequestParam (required=true)
But after testing found that the parameters in the front end and the empty string still will pass, only when you don't pass will quote parameter error
But because before understanding the annotation is wrong (think front end pass an empty string will be submitted to the parameter error), have been extensively used lead to project the annotations to do not empty test
In not before changing the source code, or not to AOP under the premise of to deal with, is there a better way (such as spring global configuration) to modify the annotation of the default behavior, make its intercept out empty string values (including don't preach to the empty string) request
thank you
CodePudding user response:
It seems no good method, may be I don't know,,,
Was tried before the actual operation, use similar to the following code to do parameter validation, returned to the caller is a clear message!
If (StringUtils. IsAnyBlank (itemId, applyName, cardId, the contactName, phoneNum)) { Return InvokeResult. Bys (" itemId, applyName, cardId, the contactName, phoneNum etc can't be empty "); }