我想重定向这样的请求
localhost:8080/firstSpringProject/{uniqueusername}
到名为“profile”的特定 Controller :
@RequestMapping(value="/profile")
public String profiles(Model model){
based on the uniqueusername i would like to render a profile page
return "profile";
}
我正在使用 spring mvc;我该如何解决这种情况,还有其他方法吗?
最佳答案
Spring 文档在 redirect view 上说:
Note that URI template variables from the present request are automatically made available when expanding a redirect URL and do not need to be added explicitly neither through Model nor RedirectAttributes. For example:
@RequestMapping(value = "/files/{path}", method = RequestMethod.POST)
public String upload(...) {
// ...
return "redirect:files/{path}";
}
请记住,低于 3.1.4 的版本会受到 memory leak due to caching redirect views 的影响。 .
如果您使用的是 Spring 3.1.3 或更低版本并且您正在这样做
return "redirect : profile?username="+username;
关于java - 使用 spring mvc 将 url 模式重定向到特定 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23320419/