ModelAttribute doesn't reflect the default value of a requestParam if null

1.4k Views Asked by At

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.

0

There are 0 best solutions below