@RequestParam check

Is there a way to check the query parameter with spring without checking it in every function? For example, each method in the controller creates a list of elements, and each method accepts "from" and "to" parameters, so the check: from >=0 && to > 0 && from < to

I want to configure spring to return BAD_REQUEST or another state, as if it could not convert the string to an int parameter.

Thanks.

+4
source share
2 answers

If you use form support objects using @RequestBody , you can use the JSR-303 bean check, where you annotate your bean form. See http://static.springsource.org/spring/docs/current/spring-framework-reference/html/validation.html#validation-beanvalidation for more details. Then you do not need to worry with Validator objects or other coding - you just comment.

+1
source

Directly, no. But if you wrap them in a class, you can have a Validator that .supports(YourClass.class) and validate(..) it.

 public class Range { private int from; private int to; //setters & getters } 
0
source

All Articles