gpt4 book ai didi

java - 我可以告诉 spring 忽略查询参数吗?

转载 作者:搜寻专家 更新时间:2023-11-01 03:36:21 25 4
gpt4 key购买 nike

如果我提交此表单:

<form id="confirmForm" method="POST">
<input type="hidden" name="guid" value="guidval"/>
</form>

到这个网址:

/AltRT?guid=guidval

映射到这个 Controller 方法:

@RequestMapping(method = RequestMethod.POST)    
public String indexPost(@RequestParam String guid)

我正在为我的 guid 获取这两个值。所以guid的值为guidval,guidval。我只想从表单中获取值。

有什么方法可以让 Spring 忽略查询字符串参数吗?

编辑以获得更多说明:查询字符串是另一个(获取)请求遗留下来的。因此,如果我可以清除同样有效的查询字符串。此外,我不想编辑表单输入的 name,因为我希望此 post 端点可用于其他服务,而无需更改它们。

最佳答案

您不能这样做,因为查询字符串将在 POST 请求的 HTTP 消息正文中发送,http://www.w3schools.com/tags/ref_httpmethods.asp

我现在想到的有两种方法

  1. 设置表单属性 Action

    <form id="confirmForm" method="POST" action="AltRT">
    <input type="hidden" name="guid" value="guidval" />
    </form>
  2. 将表单数据转换为 JSON 对象发送过来,如果必须使用原始 URL,则在 Spring 中使用 @RequestBody 捕获它。

关于java - 我可以告诉 spring 忽略查询参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30402776/

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