已解决由处理程序执行引起的异常:org.springframework.web.bind.MissingServletRequestParameterException:

时间:2018-06-27 12:53:29

标签: javascript spring-mvc

我有这个脚本,它将源名称和策略号发送到我的Spring MVC控制器。

$scope.doRepublish = function() {

    var republishSource = $scope.republishSource
    var republishPolicy = $scope.republishInput

    console.log(republishSource.name);
    console.log(republishPolicy);

    var data = new FormData();
    data.append('republishSource', republishSource);
    data.append('republishInput', republishPolicy);
    var config = {
        transformRequest: angular.identity,
        headers: {
            'Content-Type': 'application/json'
        }
    }

    var url = "/republishPolicy"
    var rowCount = null;

    var responseMessage = null;

    $http.post(url, data, config)
        .then(
            function(response) {
                $scope.republishPolicy = response.data;
                if ($scope.republishPolicy.indexOf('Success') > -1) {
                    responseMessage = "success";
                } else {
                    responseMessage = "failure";
                }

                $("#republish_alert_" + responseMessage).show()
            });
};

我在控制台中检查了一下,发现源名称和策略号的格式正确,

在处理对控制器的请求时,出现了以下异常:

  

WARN 8168 --- [nio-8092-exec-7]   .w.s.m.s.DefaultHandlerExceptionResolver:导致的已解决异常   通过处理程序执行:   org.springframework.web.bind.MissingServletRequestParameterException:   必需的字符串参数'republishSource'不存在

控制器

@RequestMapping(path = "/republishPolicy", produces = "application/json", consumes = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody String republishPolicy(@RequestParam("republishSource") String sourceSystem,
            @RequestParam("republishInput") String policyNumber)
            throws JsonParseException, JsonMappingException, IOException {
        System.out.println(sourceSystem + " , " + policyNumber);
        return overrideProcessorDao.republishPolicy(sourceSystem, policyNumber);
    }

控制台异常Console Exception

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

Spring抱怨,因为republishSource为null或不存在。

客户抱怨是因为您没有捕获到错误(您错过了陷阱)

$http.post(url, data, config).then(function() {}).catch(function(err) { console.log(err); });