gpt4 book ai didi

java - Spring URL : There's a difference between "/test" and "/test/" in the controller mapping

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

简单的 Spring Controller 示例(如果您不熟悉 Spring,只需查看输出 html):

@Controller
@RequestMapping("test")
public class TestController {
@RequestMapping("")
@ResponseBody
public String pathTest(){
return "<html><head></head><body><a href='subpath'>subpath</a></body></html>";
}
}

如果我转到http://mydomain/test,上面 html 中的链接将转到:http://mydomain/subpath

如果我转到http://mydomain/test/,则上述 html 中的链接将转到:http://mydomain/test/subpath

我想这很简单,但我不知道如何确保尾随的“/”不会影响应用程序功能。我主要担心的是,当用户手动更改 URL 时,他们可能会也可能不会留下结尾的“/”。

无论最后的“/”是否存在,我该如何确保我的应用程序能够正常工作?

最佳答案

请勿返回<a href='subpath'>subpath</a>返回

<a href='/test/subpath'>subpath</a>相反。

关于java - Spring URL : There's a difference between "/test" and "/test/" in the controller mapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5659732/

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