iteye_15162
2013-05-20 16:50
浏览 293
已采纳

springmvc中的@MatrixVariable获取参数失败

@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文档有错误?还是少了什么配置?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • jinnianshilongnian 2013-05-21 14:19
    已采纳

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

    点赞 打赏 评论
  • iteye_3429 2013-05-20 17:24

    少@PathVariable

    public void findPet([b]@PathVariable(value = "ownerId") Integer ownerId , @PathVariable(value = "petId") Integer petId[/b], @MatrixVariable Map matrixVars, @MatrixVariable(pathVar = "ownerId") Map petMatrixVars) {

    System.out.println(matrixVars);

    System.out.println(petMatrixVars);

    }

    点赞 打赏 评论

相关推荐 更多相似问题