Request Parameters and Header Values

你可以通过指定你的请求参数去精确匹配你的请求,例如像:"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")来匹配你的请求,但是我们还是推荐精确查找,不使用通配符。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章