Springng 4.X 使用@Pathvariable 注释传递变量

Sprinng 4.X passing variables with @Pathvariable annotation

我想将一些变量传递到我的服务器。我是这样做的,如示例所示:

@Controller
@RequestMapping("/owners/{ownerId}")
public class RelativePathUriTemplateController {

@RequestMapping("/pets/{petId}")
public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) {
    // implementation omitted
}
}

当我发送这样的请求时,这完全可以正常工作:

domain/owners/123/pets/123

但我想做的是得到一个主人的所有宠物。这意味着我不 need/want 传递宠物 ID:

domain/owners/123/pets/

但随后我收到一个异常消息,提示此请求没有处理程序。是否可以发送这样的请求,或者是否受到 Spring?

的限制

您必须添加第二种方法:

@RequestMapping("/pets/")
public void findPetByOwner(@PathVariable String ownerId Model model) {
    // implementation omitted
}