Required String parameter is not present
Posted williamjie
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Required String parameter is not present相关的知识,希望对你有一定的参考价值。
2017年06月28日 19:56:25
页面报Required String parameter ‘loanOrderNbr’ is not present解决办法
问题描述:
前面代码(angularjs)
var loanOrderNumber = $routeParams.loanOrderNumber;
$scope.saveButton = true;
$http.get("/test/business/order/viewDetail",{
params : {
‘loanOrderNbr‘ : loanOrderNbr
}
}).success(function(request,status){
//
}).error(function (data, status) {
//
});
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
后台代码(spring mvc)
//查看数据
@RequestMapping(value = "/viewDetail")
@ResponseBody
public AtResponse detail(@RequestParam(name = "loadOrderNbr", required = true) String loadOrderNbr) {
Map<String, Object> params = new HashMap<String, Object>();
AtResponse<TxnAcct> resp = new AtResponse(System.currentTimeMillis());
//.....
return resp;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
页面报错信息
:8080/test/business/order/viewDetail?loanOrderNbr=201706091042631 Failed to load resource: the server responded with a status of 400 (Bad Request)
- 1
当时以为是前面angularjs代码写得有问题,然而仔细对比其他功能的写法,发现没有什么区别,只是传的参数不一样而矣,非常迷惑,不解。后台也不报错(没有输出spring日志),然后将请求链接直接在浏览器中访问:
http://localhost:9770/test/business/order/viewDetail?loanOrderNbr=201706091042631
页面提示如下错误信息:
Required String parameter ‘loanOrderNbr’ is not present
发现是前端传的参数名与后端代码定义的参数名不一致导致的,囧:
前端参数是:loanOrderNbr
后端参数是:loadOrderNbr
另:网上有另一解决方法参考:
将后台代码修改为:
@RequestMapping(value = "/viewDetail")
@ResponseBody
public ResponseBase addQuestion(@RequestBody Map<String,Object> params){
String loanOrderNbr = params.get("loanOrderNbr").toString();
}
- 1
- 2
- 3
- 4
- 5
以上是关于Required String parameter is not present的主要内容,如果未能解决你的问题,请参考以下文章
Required String parameter ' ' is not present
jmeter报错Required String parameter 'auntId' is not present
报错:required string parameter XXX is not present
400错误,Required String parameter 'paramter' is not present