2012-02-15 87 views
0

我有一个配置了URI模板模式的控制器类。但是,当我从另一个控制器类重定向到此控制器时,它无法找到此处理程序方法。Spring mvc 3.1无法解析URI模板

我看到在日志中的误差,其表示“RequestMappingHandlerMapping - 没有找到处理程序方法为/ PATH2/2”。然后“未发现与URI [/ PATH2/2]中的DispatcherServlet HTTP请求映射

@Controller 
@RequestMapping("/path1") 
public class Controller1 { 

    @RequestMapping (method = MethodRequest.POST) 
    public String postMethod() { 
     // some logic 
     return "redirect:/path2/" + 2; 
    } 
} 

@Controller 
@RequestMapping("/path2/${id}") 
public class Controller2 { 

    @RequestMapping(method=RequestMethod.GET) 
    public ModelAndView getMethod(@PathVariable("id") long id) { 

    return new ModelAndView("some jsp"); 
    } 
} 

如果我将Controller2类上的RequestMapping更改为“/ path2 /”并重定向到该网址,重定向可以正常工作。 servlet上下文文件。

提前致谢!!

回答

0

语法

@RequestMapping("/path2/{id}") 

@RequestMapping("/path2/${id}") 
+0

啊!花了几个小时来调试这个。谢谢!! – bsam 2012-02-15 17:54:07