1

@RequestParam(value = "param") String param

How to validate this param in elegant way ? More exactly I must check if param is some value in database. My stack is: spring-boot+mybatis

6
  • How many values are there? Are they dynamic? Commented Mar 5, 2017 at 6:23
  • @Bohemian What does it mean dynamic ? there are three values, but I would like to only validate this one. Commented Mar 5, 2017 at 10:04
  • stackoverflow.com/questions/12146298/… Commented Mar 5, 2017 at 12:17
  • @JavaNewbie "dynamic" means they change, ie not known at compile time. If they are in a database, must you use it or would using hard coded values be OK? If the values are a known list, what are the values? Commented Mar 5, 2017 at 13:21
  • @Bohemian Values are names of columns. I am afraid of it will be changed, so I will be made to update this list. I must check if paremeter is valid columnName to prevent against SQL Injection - it is parameter for ORDER BY ? (I am using mybatis). Commented Mar 5, 2017 at 17:06

1 Answer 1

0

This might be a duplicate of that one but anyway.

There's a difference in the way you validate forms and separate parameters. With POST it's actually impossible to break the request into separate parameters and you get the whole post body, and you use @Valid to process it. With GET it is possible to have separate parameters as arguments in method, and in this case Spring proprietary @Validated annotation should be used.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, But how to use this annotation in connection to my use caes ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.