spring mvc requestmapping动态网址

时间:2014-12-19 22:04:02

标签: java spring spring-mvc controller

如何更改动态网址的请求映射。 URL可能如下所示:

当pl采用以下格式时,

是工作控制器语法:

http://zz.zz.zz.com:8080/webapp/test?Id=2&maxrows=5

@RequestMapping(value = "/test", method = RequestMethod.GET)
public @ResponseBody
void test(@RequestParam(value = "Id", required = true) String Id,
@RequestParam(value = "maxrows", required = true) int maxrows)
throws Exception 
{
System.out.println("Id: " + Id + " maxrows: " + maxrows);
}

1 个答案:

答案 0 :(得分:2)

试试这个:

@RequestMapping(value = "/test/{param1}/{param2}/{param3}")
public @ResponseBody void test(
    @RequestParam(value = "Id", required = true) String Id,
    @RequestParam(value = "maxrows", required = true) int maxrows,
    @PathVariable(value = "param1") String param1,
    @PathVariable(value = "param2") String param2,
    @PathVariable(value = "param3") String param3) {
    ...
}

有关详细信息,请查看Spring Reference Documentation