Java 如何在Spring MVC中设置获取数组参数的默认值
我有一个搜索方法,它有关键字参数。我要做的是将默认值(空字符串数组)设置为keywords参数。有没有办法做到这一点Java 如何在Spring MVC中设置获取数组参数的默认值,java,spring,spring-mvc,Java,Spring,Spring Mvc,我有一个搜索方法,它有关键字参数。我要做的是将默认值(空字符串数组)设置为keywords参数。有没有办法做到这一点 @GetMapping(value = "search") public List<Integer> search(@RequestParam String[] keywords){ return calculate(Arrays.asList(keyword)); } @GetMapping(value=“search”) 公共列表搜索(@RequestPara
@GetMapping(value = "search")
public List<Integer> search(@RequestParam String[] keywords){
return calculate(Arrays.asList(keyword));
}
@GetMapping(value=“search”)
公共列表搜索(@RequestParam String[]关键字){
返回计算(Arrays.asList(关键字));
}
尝试使用以下方法:
@RequestParam(value="keywords[]", required=false) String[] keywords
或
请尝试使用以下选项:
@RequestParam(value="keywords[]", required=false) String[] keywords
或
@RequestParam
具有设置默认值的属性defaultValue
public List<Integer> search(@RequestParam(defaultValue="default value") String[] keywords){
return calculate(Arrays.asList(keyword));
}
公共列表搜索(@RequestParam(defaultValue=“default value”)字符串[]关键字){
返回计算(Arrays.asList(关键字));
}
@RequestParam
具有设置默认值的属性defaultValue
public List<Integer> search(@RequestParam(defaultValue="default value") String[] keywords){
return calculate(Arrays.asList(keyword));
}
公共列表搜索(@RequestParam(defaultValue=“default value”)字符串[]关键字){
返回计算(Arrays.asList(关键字));
}
你是说这个答案吗?你是说这个答案吗