如何使用AngularJS将多个参数发送到JAVA API

How to Send Multiple params to JAVA API using AngularJS

本文关键字:JAVA API 参数 何使用 AngularJS      更新时间:2023-09-26

我有如下的Java API函数:

     public Response abc(@FormParam("tenderIdsJsonArray") JSONArray tenderIdsJsonArray, @FormParam("tenderRejectTime") String tenderRejectTime,@FormParam("rejectResonType")  String rejectResonType) {
     }

我从AngularJs 发送数据

     $http({
      method: 'POST',
      url: URL,
      data: {bacJsonArray:[1543],RejectTime:"12",rejectResonType:"test"}    
    }).success(function (response) {
      loaderServ.hide();
      resolve(response);
    }).error(function (error) {
      loaderServ.hide();
      reject(error);
    });

我在API端的中得到了函数的所有参数为空

我需要在哪里更改

我还尝试发送:

JSON.stringify({bacJsonArray:[1543],RejectTime:"12",rejectResonType:"test"} 
    })

或params:{alldata}

我还尝试在服务器端更改:

     public Response abc(JSONArray bacJsonArray,String RejectTime,String rejectResonType) {
     }

但在所有情况下,我都在服务器端上收到Null

下面是我使用的方法和它的工作原理。

    $http({
        method: 'POST',
        url: url,
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        transformRequest: function(obj) {
            var str = [];
            for(var p in obj)
            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
            return str.join("&");
        },
        data: {username: $scope.userName, password: $scope.password}
    }).success(function () {});
var req = {
    method: 'POST',
    url: 'http://example.com',
    data: { test: 'test' }
};
$http(req).then(function(){
    // success
}, function(){
    error
});