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,393
  • 25
  • 82
  • 148
  • did you mean this https://stackoverflow.com/questions/4596351/binding-a-list-in-requestparam exactly this answer https://stackoverflow.com/a/5624006/5558072 – Youcef LAIDANI 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,496
  • 3
  • 23
  • 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
  • 14,872
  • 15
  • 58
  • 85