页面报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) {
//
});
后台代码(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;
}
页面报错信息
:8080/test/business/order/viewDetail?loanOrderNbr=201706091042631 Failed to load resource: the server responded with a status of 400 (Bad Request)
当时以为是前面angularjs代码写得有问题,然而仔细对比其他功能的写法,发现没有什么区别,只是传的参数不一样而矣,非常迷惑,不解。后台也不报错(没有输出spring日志),然后将请求链接直接在浏览器中访问:
http://localhost:9770/test/business/order/viewDetail?loanOrderNbr=201706091042631
页面提示如下错误信息:
required String parameter ‘loanOrderNbr’ is not present
发现是前端传的参数名与后端代码定义的参数名不一致导致的,囧:
前端参数是:loanOrderNbr
后端参数是:loadOrderNbr
@H_404_80@另:网上有另一解决方法参考:@RequestMapping(value = "/viewDetail")
@ResponseBody
public ResponseBase addQuestion(@RequestBody Map<String,Object> params){
String loanOrderNbr = params.get("loanOrderNbr").toString();
}