0

I'm using Spring Framework and I want to get query string values in Controller

api/asset?param1=value&param2=value

some parameters can be empty like this

api/asset?param1=value&param2

Here is code for controller

@RequestMapping(value = "/api/assets", method = RequestMethod.GET)
public @ResponseBody String getAssetList(
        @RequestParam("limit") int limit,
        @RequestParam("offset") int offset
        ) {

}

I got it working when both parameters are given, but I cannot get values when one parameter is empty

1
  • If the parameter is empty, it is a bad formed query string. Commented Jun 5, 2014 at 16:34

1 Answer 1

3

Parameters are mandatory by default but you can set them as optional.

Take a look at spring documentation here:

http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#mvc-ann-requestparam

Parameters using this annotation are required by default, but you can specify that a parameter is optional by setting @RequestParam's required attribute to false (e.g., @RequestParam(value="id", required=false)).

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.