天天看點

[email protected](請求參數) & @RequestHeader(請求頭)&@CookieValue(7)

1.在處理方法入參處使用 @RequestParam 可以把請求參 數傳遞給請求方法。

請求:

<a href="springMVC/testRequestParam?username=lihenhuan&age=11" target="_blank" rel="external nofollow" >testRequestParam</a>
           

擷取:前面所學到的@PathVariable是擷取請求URL中的占位符,@RequestParam是擷取請求參數。

/**
* @RequestParam來映射請求參數。
*   value:請求參數的參數名
*   required:該參數是否必須。預設true
*   defaultValue:請求參數的預設值。
* @param username
* @param age
* @return
*/
@RequestMapping("/testRequestParam")
public String testRequestParam(@RequestParam(value="username") String username
		,@RequestParam(value="age",required=false,defaultValue="0") int age) {
	System.out.println("testRequestParam username : " +username +"age : "+age);
	return SUCCESS;
}
           

2.請求頭包含了若幹個屬性,伺服器可據此獲知用戶端的資訊,通過 @RequestHeader 即可将請求頭中的屬性值綁

  定到處理方法的入參中

[email protected](請求參數) &amp; @RequestHeader(請求頭)&amp;@CookieValue(7)

[email protected] 可讓處理方法入參綁定某個 Cookie 值

[email protected](請求參數) &amp; @RequestHeader(請求頭)&amp;@CookieValue(7)

繼續閱讀