简体   繁体   English

在 Spring Boot 中,我们可以通过 @PathVariable 或 @RequestParam 之类的 URL 将锚标记作为变量传递吗?

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

I would like to use URL http://localhost:8080/blog#section & obtain #section as a variable in getBlog() method.我想使用 URL http://localhost:8080/blog#section 并获取 #section 作为 getBlog() 方法中的变量。

// localhost:8080/blog#section
@GetMapping("/blog/{section}")
public String getBlog(Model model, @PathVariable("section") String section){
    return "blog" + section; // localhost:8080/blog#section
}

The #section part is never sent to server ( see this answer ),so what you are demanding is impossible. #section部分永远不会发送到服务器( 请参阅此答案),因此您的要求是不可能的。

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.实际上#section用于浏览器定位网页的内容,而不是用于服务器决定返回哪些内容。

What you are demanding can be easyily achieved with a query like localhost:8080/blog?section=?使用localhost:8080/blog?section=?类的查询可以轻松实现您的要求localhost:8080/blog?section=? or a url path like localhost:8080/blog/section或者像localhost:8080/blog/section这样的 url 路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 引导 - 如何区分 @PathVariable 和查询参数 (@RequestParam) 的验证 - Spring Boot - how to differentiate between validation for @PathVariable and query params (@RequestParam) 尝试两个在thymeleaf / spring-boot中通过@PathVariable传递两个对象 - Attempting two pass two objects through @PathVariable in thymeleaf/spring-boot 如何将URL作为@PathVariable传递给Spring RestController? - How to pass url as @PathVariable to spring RestController? Spring Boot 使用路径变量从 url 获取 id - Spring boot using pathvariable to get hold of an id from url 在Spring(Boot)中使用@RequestMapping和@PathVariable捕获变量路径的任何方法? - Any way to use @RequestMapping and @PathVariable in Spring (Boot) to capture a variable path? 如何将未知的传入 requestParam 传递给 spring boot 中的帖子? - How to pass an unknown incoming requestParam to a post in spring boot? 如何在@Requestparam java spring 引导中传递加密值 - How to pass encrypted value in @Requestparam java spring boot Spring Boot @RequestParam截断了用?和&#39;s传入的URL - Spring Boot @RequestParam truncating URL's passed in with ?'s and #'s @RequestParam地图 <String, String> 在Spring Boot中将变量名称打印为键 - @RequestParam Map<String, String> Prints variable name as key in spring boot 通过 Spring 中的 @RequestParam 发送 % - Sending % through @RequestParam in Spring
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM