我有以下两种控制器方法,当我向其发布JSON(响应为200)时,/garages/a
可以工作,但是/garages/a/brand
却提供404。
它们仅因映射值而不同。
我正在使用Spring 4.1.4.RELEASE和Java配置。我没有使用Spring Boot。
控制器方法:
@RequestMapping(value = "/garages/a", method = RequestMethod.POST, headers = "Content-Type = application/json", produces = "application/json")
public Garage specificGaragePost(
@RequestBody Garage garage) {
return garage;
}
@RequestMapping(value = "/garages/a/brand", method = RequestMethod.POST, headers = "Content-Type = application/json", produces = "application/json")
public Garage specificGarageBrandPost(
@RequestBody Garage garage) {
return garage;
}
车库课
public class Garage {
private String id;
private String brand;
private List<Fuel> fuels;
private double[] location;
//Getters and setters left out for brevity
JSON示例(适用于/ garages / a URL,但不适用于/ garages / a / brand)
{
"id": "some-id",
"brand": "brand",
"fuels": [],
"location": [0,0]
}
最佳答案
因为找到/garages/a/brand
时,会将其视为带有参数品牌的/garages/a/
,但/garages/a/
不接受任何参数。