Java – spring MVC empty array as default

I have a spring controller method that takes some optional arrays as parameters They are not required, but I hope they are not null, but empty arrays when they are not in the parameters received by the controller method I know that I can check if they are null and assign them as new objects, but this will produce a lot of boilerplate code In addition, when I try to do something like this:

@RequestMapping(headers = "Accept=application/json",method = RequestMethod.GET,value = "/socialUsers/saveFilter",produces = "application/json")
public @ResponseBody
void saveFilterToDataBase(@RequestParam(required = false,value = "gender",defaultValue = "{}") Gender[] genders)

....

I received the 400th error, which was strange when I didn't provide parameters in the URL, resulting in the required field being false

Guys, what do you think?

Solution

A solution was found The default empty array value is only '' The problem is that even if the parameter is not required, it will raise the 400th error strange. I'm trying

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>