Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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
Spring mvc @请求映射&;有界泛型参数_Spring Mvc_Generics_Java 8_Request Mapping - Fatal编程技术网

Spring mvc @请求映射&;有界泛型参数

Spring mvc @请求映射&;有界泛型参数,spring-mvc,generics,java-8,request-mapping,Spring Mvc,Generics,Java 8,Request Mapping,以下@RequestMapping为Spring Boot 1.5/Java 8中的@RestController生成了一个不明确的请求映射 有没有办法“否定”第一个方法上的泛型约束,使其不包含Iterable?我希望保持相同的方法名、路径等。。 (即)带有数组的post将转到一个方法,单个项目的post将转到第二个方法 @RequestMapping(method = RequestMethod.POST, value="/foo") public T save(T item){ ..

以下
@RequestMapping
为Spring Boot 1.5/Java 8中的
@RestController
生成了一个不明确的请求映射

有没有办法“否定”第一个方法上的泛型约束,使其不包含
Iterable
?我希望保持相同的方法名、路径等。。 (即)带有数组的post将转到一个方法,单个项目的post将转到第二个方法

@RequestMapping(method = RequestMethod.POST, value="/foo")
public T save(T item){
    ...
}
@RequestMapping(method = RequestMethod.POST, value="/foo")
public Iterable<T> save(Iterable<T> items){
    ...
}
@RequestMapping(method=RequestMethod.POST,value=“/foo”)
公共T保存(T项){
...
}
@RequestMapping(method=RequestMethod.POST,value=“/foo”)
公共可编辑保存(可编辑项){
...
}

您的映射显然不明确

您需要为每个保存的类型指定不同的端点,或者可以通过
@RequestMapping
注释的元素缩小映射范围

例如,您可以实现如下内容:

@RequestMapping(method = RequestMethod.POST, value="/foo", params="item")
public T save(T item){
    ...
}
@RequestMapping(method = RequestMethod.POST, value="/foo", params="items")
public Iterable<T> save(Iterable<T> items){
    ...
}

使用这些参数,您无法定义端点。太好了,出于某种原因,我认为参数的“类型”足以使方法过载。
@RequestMapping(method = RequestMethod.POST, value="/foo", headers="Input-Type=item")
public T save(T item){
    ...
}
@RequestMapping(method = RequestMethod.POST, value="/foo", headers="Input-Type=items")
public Iterable<T> save(Iterable<T> items){
    ...
}