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){
...
}