0

I have the below spring rest API :

@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponsePack getPacks(HttpServletRequest request, @RequestParam(value = "effDate", required = false) String effDate, @RequestParam(value = "cardType", defaultValue = "*") String cardType, @Valid @ModelAttribute Wrapper requestParamWrapper) {

effDate and cardType are the two params passed to this API (both are optional).

What I'm trying to do is set a default value of * to cardType if nothing is passed.

I can see that the String cardType has got the correct default value. How do i do something similar for the requestParamWrapper's cardType (in the model attribute) , i.e setting the default value * for cardType when the param is not passed.

5
  • 1
    Why should it. The request param doesn't influence the binding. Commented Sep 15, 2017 at 9:34
  • duplicate of stackoverflow.com/questions/12296642/… Commented Sep 15, 2017 at 9:43
  • How do I do that binding ? Commented Sep 15, 2017 at 9:43
  • What is Wrapper? Is that your own class? You can set defaults using the set-method for that field. Commented Sep 15, 2017 at 10:37
  • @JackFlamp , Yeah my custom class, and yes I'm currently using setter. Just looking for any alternate annotations or something? Commented Sep 15, 2017 at 12:22

0

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.