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

jla*_*s62 5 java spring spring-4

如果我提交此表格:

<form id="confirmForm" method="POST">
    <input type="hidden" name="guid" value="guidval"/>
</form>
Run Code Online (Sandbox Code Playgroud)

到这个网址:

/AltRT?guid=guidval

映射到这个控制器方法:

@RequestMapping(method = RequestMethod.POST)    
public String indexPost(@RequestParam String guid)
Run Code Online (Sandbox Code Playgroud)

我为我的 guid 获得了两个值。所以价值guid就是guidval,guidval。我只想从表单中获取值。

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

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

Din*_* Tw 1

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

我现在能想到的有两种方法

  1. 设置表单属性动作

    <form id="confirmForm" method="POST" action="AltRT">
        <input type="hidden" name="guid" value="guidval" />
    </form>
    
    Run Code Online (Sandbox Code Playgroud)
  2. @RequestBody如果必须使用原始 URL,请将表单数据转换为 JSON 对象以将其发送出去,然后在 Spring 中捕获它。