0 0

springmvc中的@MatrixVariable获取参数失败0

@RequestMapping(value = "/owners/{ownerId}/pets/{petId}", method = RequestMethod.GET)
    public void findPet(@MatrixVariable Map<String, String> matrixVars, @MatrixVariable(pathVar = "ownerId") Map<String, String> petMatrixVars) {
        System.out.println(matrixVars);
        System.out.println(petMatrixVars);
    }

 上面代码是spring文档中的例子,浏览器中输入:http://localhost:8080/owners/44/pets/55;q=22,33;s=23时,控制台输出:

{q=[22, 33], s=[23]}
{q=[22, 33], s=[23]}

 

但是当输入http://localhost:8080/owners/42;q=11;r=12/pets/55;q=22,33;s=23则findPet方法没有执行,难道spring文档有错误?还是少了什么配置?


问题补充:public void findPet(@MatrixVariable Map<String, String> matrixVars, @MatrixVariable(pathVar = "ownerId") Map<String, String> petMatrixVars)中的ownerId应该改为petId
 
2013年5月20日 16:50

2个答案 按时间排序 按投票排序

0 0

采纳的答案

估计是bug,已提交给springsource,具体分析请看
http://jinnianshilongnian.iteye.com/blog/1872760

2013年5月21日 14:19
0 0

少@PathVariable

public void findPet(@PathVariable(value = "ownerId") Integer ownerId , @PathVariable(value = "petId") Integer petId, @MatrixVariable Map<String, String> matrixVars, @MatrixVariable(pathVar = "ownerId") Map<String, String> petMatrixVars) { 
        System.out.println(matrixVars); 
        System.out.println(petMatrixVars); 
    } 

2013年5月20日 17:24

相关推荐

Global site tag (gtag.js) - Google Analytics