java - 当我们在 url 路径参数中传递 # 而不是 Integer 时,为什么它接受 '#' 而不是 Integer?

标签 java url integer

在 Spring Boot 应用程序中进行 get 操作时, 就像 api/getbooks/1 :它获取第一条记录。 对于 api/getbooks/@ :给出无效参数。 但是 api/getbooks/1# :给出与 api/getbooks/1 相同的结果。 我怎样才能不接受#?

最佳答案

在维基百科上的URL片段文章中可以找到

The fragment identifier functions differently to the rest of the URI: its processing is exclusively client-side with no participation from the web server, ... When an agent requests a web resource from a Web server, the agent sends the URI to the server, but does not send the fragment

所以这基本上是预期的行为, # 以及之后的所有内容都不会发送到服务器。因此,两个查询的 URL 服务器获取的内容是相同的。

关于java - 当我们在 url 路径参数中传递 # 而不是 Integer 时,为什么它接受 '#' 而不是 Integer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55586362/

相关文章:

python - 试图在 Python 的字符串的特定部分中查找所有唯一值

android - SMS 文本中的自定义方案

java - java 将字符串中的数字转换为列表

java - 为什么写入文件的整数会被读取为不同的值?

java - 截图程序

Java 8 流过滤器

java.lang.NoClassDefFoundError : [generic] at dalvik. system.NativeStart.main(本地方法)

java - 有没有办法在java中使用Thread在JPanel上绘制图形?

python - 如何标准化 Python 字符串编码

java - 在 Java 中设置一个整数的范围