spring mvc请求映射动态url

use*_*951 4 java spring controller spring-mvc

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

当 url 采用这种格式时,控制器的工作语法如下:

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);
}
Run Code Online (Sandbox Code Playgroud)

Luk*_*sko 5

尝试这个:

@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) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅Spring 参考文档