@RequestMapping的精確映射

@RequestMapping一共有四個屬性,分別爲values,method,params及headers分別表示請求URL,請求方法,請求參數及請求頭文件的映射條件。他們之間是與的關係。html

param1:表示請求必須包含爲param1的參數spring

!param1:表示不包含爲parpm1的參數mvc

public class helloworldhandler {
	@RequestMapping(value="/hello",method=RequestMethod.GET,params= {"name=tom","age!=12"},headers={"accept=text/class"})
	public String hello() {
		System.out.println("歡迎走進spring MVC,你建立的第一個方法成功了");
		return "success";
	}

}
<title>Insert title here</title>
</head>
<body>
<a href="springmvc/hello?name=tom&&age=12">hello world</a>
</body>
</html>

不符合條件便出現400錯誤(我看教程出現的是405,,,,,這個問題請大神或者之後成爲大神的本身回答吧,,,,哈哈哈)app

感受這個精準化映射原理比較簡單,可是引號的位置老是打不對,,因此在複習下code

value="/hello(映射處理的路徑)"htm

method=RequestMethod.GET(POST)教程

HTML就是get方式的請求get

params={"name=tom","age!=12"}it

一個集合,可包含多個條件class

headers={"accept=text/html"}

也是一個集合,定義請求頭文件的類型等。

相關文章
相關標籤/搜索