英文:
In Spring Boot, can we pass anchor tag, as a variable, through URL like @PathVariable or @RequestParam?
问题
我想使用URL http://localhost:8080/blog#section,并在getBlog()方法中获取#section作为一个变量。
// localhost:8080/blog#section
@GetMapping("/blog/{section}")
public String getBlog(Model model, @PathVariable("section") String section){
return "blog" + section; // localhost:8080/blog#section
}
英文:
I would like to use URL http://localhost:8080/blog#section & obtain #section as a variable in getBlog() method.
// localhost:8080/blog#section
@GetMapping("/blog/{section}")
public String getBlog(Model model, @PathVariable("section") String section){
return "blog" + section; // localhost:8080/blog#section
}
答案1
得分: 2
#section部分从不发送到服务器(参见此答案),所以你要求的是不可能的。
实际上,#section用于浏览器定位网页的内容,而不是用于服务器决定返回哪个内容。
你要求的可以通过像localhost:8080/blog?section=?
这样的查询或者像localhost:8080/blog/section
这样的URL路径轻松实现。
英文:
The #section part is never sent to server (see this answer),so what you are demanding is impossible.
In fact #section is used for browser to locate the content of a web page, it's not used for server to decide which content to return.
What you are demanding can be easyily achieved with a query like localhost:8080/blog?section=?
or a url path like localhost:8080/blog/section
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论