![](/img/trans.png)
[英]How can you have two URL routes mapped to the same handler method in Spring MVC (3.0)?
[英]How do you switch between two request mappings handled by the same Spring MVC mapping handler?
@RequestMapping(value = {"/abc", "/def"} method = RequestMethod.GET)
public final String switch(HttpServletRequest request, ModelMap model)
throws Exception {
// pseudeocode:
if mapping == "abc"
return "redirect:/def";
else
process the request;
}
如果要調用abc
處理程序,我想重定向到def
。
是否可以在處理“ def”的同一處理函數中執行此操作?
我認為,最好使用@RequestMapping(“ abc”)創建另一個方法,該方法將重定向到def。 如果您不想這樣做,則可以從HttpServletRequest獲取路徑信息(查看javadoc),並執行if語句來進行重定向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.