1

I have a search method and it has keywords parameter. What I want to do is set a default value(empty String array) to keywords parameter. Is there any way to do this?

@GetMapping(value = "search")
public List<Integer> search(@RequestParam String[] keywords){
 return calculate(Arrays.asList(keyword));
}
hellzone
  • 5,076
  • 21
  • 77
  • 133
  • did you mean this https://stackoverflow.com/questions/4596351/binding-a-list-in-requestparam exactly this answer https://stackoverflow.com/a/5624006/5558072 – YCF_L Nov 27 '17 at 08:58

2 Answers2

0

Try to use below:

@RequestParam(value="keywords[]", required=false) String[] keywords

or

 @RequestParam(value=" ", required=false) String[] keywords
Raju Sharma
  • 2,456
  • 3
  • 22
  • 41
0

@RequestParam has an attribute defaultValue to set default value.

public List<Integer> search(@RequestParam(defaultValue="default value") String[] keywords){
 return calculate(Arrays.asList(keyword));
}
Mehraj Malik
  • 13,242
  • 15
  • 52
  • 81