gpt4 book ai didi

java - 使用 spring mvc 将 url 模式重定向到特定 Controller

转载 作者:行者123 更新时间:2023-11-29 05:24:15 25 4
gpt4 key购买 nike

我想重定向这样的请求

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;

你会看到OutOfMemoryError sometime .

关于java - 使用 spring mvc 将 url 模式重定向到特定 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23320419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com