RFC3986定義了在URI中包含name-value的規範!這也是spring4.0衆多吸引人的新特性之一。先來舉個小例子: java
好比URI是這樣的: spring
//GET /pets/42;q=11;r=22 app
對應的方法定義則是: ui
@RequestMapping(value = "pets/{petId}, method = RequestMethod.GET) public void findPet(@PathVariable String petId,@MatrixVariable int q){ ... }
好比你的URI是: spa
//GET /owners/42;q=11/pets/21;q=22 code
@RequestMapping(value = "/owners/{ownerId/pets/{petId}", method = RequestMethod.GET) public void findPet( @MatrixVariable(value = "q",pathVar="ownerId") int q1, @MatrixVariable(value = "q",pathVar="petId") int q2) }
此處q1=11,q2=22. class
固然也能夠使用Map做爲方法入參: require
好比你的URI爲: request
//GET /owners/42;q=11;r=12/pets/21;q=22;s=23 方法
對應方法爲:
@RequestMapping(value = "/owners/{ownerId}/pets/{petId}", method = RequestMethod.GET) public void findPet( @MatrixVariable Map<String,String> matrixVars, @MatrixVariable(pathVar = "petId") Map<String,String> petMatrixVars){ ... }
matrixVars = ["q" : [11,22], "r" : 12, "s" : 23]
petMatrixVars = ["q" : 11,"s" : 23]
以上例子來自reference,因此想深刻了解spring 4.0或者javaconfig或者spring boot等玩意,去看reference吧!