gpt4 book ai didi

javascript - 可能未处理的拒绝 : - When trying to pass data from angularJS to spring MVC

转载 作者:行者123 更新时间:2023-11-30 14:22:43 25 4
gpt4 key购买 nike

这个错误对我的考验很大。有人可以帮助我做错什么吗?

我有一个脚本,它以 JSON 格式保存几个参数的值。

var mpdApp = angular.module('mpdApp', ['ngAnimate',
'ngSanitize', 'ui.bootstrap'
]);

mpdApp
.controller(
'mpdController',
[
'$scope',
'$rootScope',
'$http',
'$window',

function($scope, $rootScope, $http, $window) {
$scope.doValidation = function() {

var mpdData = {
'mpdPolicyNumber': $scope.mpdPolicyNumber,
'mpdFirstName': $scope.mpdFirstName,
'mpdLastName': $scope.mpdLastName,
'mpdAddress': $scope.mpdAddress,
'mpdPhoneNumber': $scope.mpdPhoneNumber
};

console.log(mpdData);

$http({
'url': '/mpdValidate',
'method': 'POST',
'headers': {
'Content-Type': 'application/json'
},
'params': mpdData
})
.then(
function(response) {
$rootScope.resultMpdData = response.data;
});
};
}
]);

当我尝试通过 POST 将其传递给我的 spring mvc Controller 时,

spring mvc Controller 方法:

@PostMapping(path = "/mpdValidate", produces = "application/json")
@ResponseBody
public List<MPDValidationOutputVO> mpdValidate(@RequestParam("mpdPolicyNumber") String mpdPolicyNumber,
@RequestParam("mpdFirstName") String mpdFirstName, @RequestParam("mpdLastName") String mpdLastName,
@RequestParam("mpdAddress") String mpdAddress, @RequestParam("mpdPhoneNumber") String mpdPhoneNumber)
throws JsonParseException, JsonMappingException, IOException {

System.out.println("*************");
MPDValidationInputVO mpdValidationInput = new MPDValidationInputVO();
List<MPDValidationOutputVO> mpdValidationOutput = mpdValidationService.mpdValidate(mpdValidationInput);
return mpdValidationOutput;
}

我收到这个错误。 error

控制台日志:

{mpdPolicyNumber: "werwer", mpdFirstName: "czxc", mpdLastName: "werwe", mpdAddress: "ghhdf", mpdPhoneNumber: "asaa"}

感谢您的帮助。

最佳答案

尝试使用这个变体

$http({
url: 'request-url',
method: "POST",
data: { 'message' : message }
})

因为url已经是一个参数,你不应该用单引号引用它。

关于javascript - 可能未处理的拒绝 : - When trying to pass data from angularJS to spring MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52477782/

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