你可以通過指定你的請求參數去精確匹配你的請求,例如像:"myParam", "!myParam", or "myParam=myValue"。
前兩個是請求參數存在/不存在的問題,而第三個是去精確的指定請求參數值,請看下面的例子:
@Controller
@RequestMapping("/owners/{ownerId}")
public class RelativePathUriTemplateController {
@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, params = "myParam=myValue")
public void findPet(@PathVariable String ownerId,@PathVariable String petId, Model model) {
// implementation omitted
}
}
下面是通過header的值來做的相同的事情,例子:
@Controller
@RequestMapping("/owners/{ownerId}")
public class RelativePathUriTemplateController {
@RequestMapping(value = "/pets", method = RequestMethod.GET, headers = "myHeader=myValue")
public void findPet(@PathVariable String ownerId,@PathVariable String petId, Model model) {
// implementation omitted
}
}
雖然你可以使用media type 的通配符("content-type=text/*" will match to "text/plain" and "text/html")來匹配你的請求,但是我們還是推薦精確查找,不使用通配符。