Java 异常:org.springframework.web.bind.MissingServletRequestParameterException:所需的字符串参数“params”不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37107570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exception: org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'params' is not present
提问by Vanan
When i clicked the edit button the values from dataTable should display in form. But somehow it doesn't work. Below are my codes for reference.
当我单击编辑按钮时,dataTable 中的值应显示在表单中。但不知何故它不起作用。下面是我的代码供参考。
Call DataTable:
调用数据表:
$("#tranTable").on("click", "#edit", function(){
var row = $(this).closest("tr");
$("#Own-Account").removeClass("hidden");
$("fieldset#addToListMethod").addClass("hidden");
$("fieldset#Own-Account #templateTrxId").val( row.find("[name$=templateTrxId]").val() )
$("fieldset#Own-Account #templateId") .val( row.find("[name$=templateId]").val() )
$("fieldset#newFT #fromAccNo") .val( row.find("[name$=fromAccNo]").val() ),
$("fieldset#newFT #methodOfTransfer") .val( row.find("[name$=methodOfTransfer]").val() ),
$("fieldset#Own-Account #toAccNo") .val( row.find("[name$=toAccNo]").val() ),
$("fieldset#Own-Account #paymentRef") .val( row.find("[name$=paymentRef]").val() ),
$("fieldset#Own-Account #amount") .val( row.find("[name$=amount]").val() ),
//hidden
$("fieldset#Own-Account #otherPaymentDetail").val( row.find("[name$=otherPaymentDetail]").val() ),
$("fieldset#Own-Account #email1").val( row.find("[name$=email1]").val() ),
$("fieldset#Own-Account #email2").val( row.find("[name$=email2]").val() ),
$("fieldset#Own-Account #sms1").val( row.find("[name$=sms1]").val() ),
$("fieldset#Own-Account #sms2").val( row.find("[name$=sms2]").val() ),
$("fieldset#Own-Account #purpose").val( row.find("[name$=purpose]").val() )
$("fieldset#Own-Account #isEdit").val(1);
$("fieldset#Own-Account #dataTableRowId").val(row.data("row-id"));
});
采纳答案by FreezY
From the exception,your problem are likely to be found because the @RequestMapping
doesn't found the parameter being send from previous page.
由于@RequestMapping
没有找到从上一页发送的参数,因此很可能会发现您的问题。
In this case is likely like this:
在这种情况下可能是这样的:
@RequestMapping(value = "/check")
public String getID(@RequestParam(value = "params") String params){
//your logic code here
}
From here,the exception come when the @RequestMapping
doesnt found "params"
:
从这里开始,当未@RequestMapping
找到时出现异常"params"
:
@RequestParam(value = "params") String params
This happen because by default @RequestParam
will try to get the value and return an exception when the value was not found.
发生这种情况是因为默认情况下@RequestParam
会尝试获取该值并在未找到该值时返回异常。
So you have two ways to resolve this,
所以你有两种方法可以解决这个问题,
1) You can supply the URL /check
with params
variable or,
1) 您可以提供/check
带有params
变量的 URL ,或者,
2) You can change the @RequestParam
requirement to false like this:
2)您可以@RequestParam
像这样将要求更改为false:
@RequestParam(value = "params", required = false) String params
Take note that this is example to reflect your scenario and problem. Gud luk.
请注意,这是反映您的场景和问题的示例。咕噜。
回答by RotS
I had the same error message. My mistake was that I wrote on Javascript side:
我有同样的错误信息。我的错误是我在 Javascript 方面写的:
MyService.getStatus(vm.id);
instead of:
代替:
MyService.getStatus({id : vm.id});
so the parameter was not named as expected on Java side:
所以参数在 Java 端没有按预期命名:
@GetMapping("/myservice/getStatus")
@Timed
public ResponseEntity<String> getStatus(@RequestParam("id") Long id) {