2010-10-12 73 views
2

我有AA userPanel方法映射到/user/panel URL路徑:如何將兩個URL路由映射到Spring MVC(3.0)中的相同處理程序方法?

@RequestMapping(value = "/user/panel", method = RequestMethod.GET) 
public final String userPanel(HttpServletRequest request, ModelMap model) 

不過,我也很喜歡userPanel方法來處理路線/panel而無需創建一個單獨的方法,像這樣:

@RequestMapping(value = "/panel", method = RequestMethod.GET) 
public final String panel(HttpServletRequest request, ModelMap model) 

有沒有辦法讓userPanel方法處理兩條路線以避免重複?

回答

8

@RequestMapping可以採取多個路徑:

@RequestMapping(value = {"/user/panel", "/panel"}, method = RequestMethod.GET) 
public final String userPanel(HttpServletRequest request, ModelMap model) 
相關問題