spring的版本 4.2.4.RELEASE
矩陣變量###
在路徑段落中攜帶鍵值對(duì)
/**
* 需要開(kāi)啟 <mvc:annotation-driven enable-matrix-variables="true"/>
* 請(qǐng)求;/test/123;q=123/h/456;q=456
* @param q1
* @param q2
*/
@RequestMapping(path = "/test/{ownerId}/h/{petId}")
public void findPet(@MatrixVariable(name = "q", pathVar = "ownerId") int q1, @MatrixVariable(name = "q", pathVar = "petId") int q2) {
System.out.println(q1+"---"+q2);
}
/**
* 更復(fù)雜的示例
* 請(qǐng)求:/test2/123;q=123;r=222;m=4/h/456;q=456;p=234
* 結(jié)果:m1 {"q":["123","456"],"r":["222"],"m":["4"],"p":["234"]}
* m2 {"q":["456"],"p":["234"]}
*
* 需要使用阿里巴巴的fastjson
* <dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.3</version>
</dependency>
* @param m1
* @param m2
*/
@RequestMapping(path = "/test2/{ownerId}/h/{petId}")
public void findPet2(@MatrixVariable Map<String, String> m1, @MatrixVariable(pathVar = "petId") Map<String, String> m2) {
System.out.println(JSON.toJSONString(m1));
System.out.println(JSON.toJSONString(m2));
}