相关疑难解决方法(0)

使用Spring 3.0,我可以创建一个可选的路径变量吗?

使用Spring 3.0,我可以有一个可选的路径变量吗?

例如

@RequestMapping(value = "/json/{type}", method = RequestMethod.GET)
public @ResponseBody TestBean testAjax(
        HttpServletRequest req,
        @PathVariable String type,
        @RequestParam("track") String track) {
    return new TestBean();
}
Run Code Online (Sandbox Code Playgroud)

在这里,我想/json/abc/json称为相同的方法.
一个明显的解决方法是声明type为请求参数:

@RequestMapping(value = "/json", method = RequestMethod.GET)
public @ResponseBody TestBean testAjax(
        HttpServletRequest req,
        @RequestParam(value = "type", required = false) String type,
        @RequestParam("track") String track) {
    return new TestBean();
}
Run Code Online (Sandbox Code Playgroud)

然后/json?type=abc&track=aa/json?track=rr将工作

rest spring

175
推荐指数
6
解决办法
14万
查看次数

标签 统计

rest ×1

spring ×1