如何在由同一个Spring MVC映射处理程序处理的两个请求映射之间切换


@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语句做重定向。

最新更新