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 ");
}

CodePudding user response:

reference 1/f, young love code 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 ");
}
written as feeling a little ugly, just found this problem, today also didn't want to know why the spring such processing, feel in HTTP, judgment parameters exist not only not much meaning
Currently only aop to cut

CodePudding user response:

You're right ah, if can process the best aop global,
Accustomed to, now I get and post parameters of springboot code every time short check, basically check control class code

CodePudding user response:

Don't JSR - 303 do input validation or JSR - 349

CodePudding user response:

young love code reference 4 floor response:
no JSR - 303 or JSR - 349 do input validation
this will be a large number of modifying existing code is more trouble finally cut aop

CodePudding user response:

quoted salty hum restaurant reply: 3/f
you're right ah, if can handle the best aop global,
Accustomed to, now I get and post parameters of springboot code every time short calibration, control class code are basically check
eventually cut

CodePudding user response:

HandlerMethodArgumentResolver in Spring is used to handle the Controller parameter interface, can spend a little time, design a @ RequestParam similar comments
  • Related