Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Spring MVC中设置获取数组参数的默认值_Java_Spring_Spring Mvc - Fatal编程技术网

Java 如何在Spring MVC中设置获取数组参数的默认值

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

我有一个搜索方法,它有关键字参数。我要做的是将默认值(空字符串数组)设置为keywords参数。有没有办法做到这一点

@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(关键字));
}
你是说这个答案吗?你是说这个答案吗