In Spring Boot, can we pass anchor tag, as a variable, through URL like @PathVariable or @RequestParam?

huangapple go评论71阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年10月9日 04:49:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/64270406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定