【问题标题】:How to send a list type param from angular js to java rest controller如何将列表类型参数从 Angular js 发送到 java rest 控制器
【发布时间】:2017-02-17 06:53:31
【问题描述】:

我想从 angular js 发送字符串列表,其中我的控制器编码为

 @POST
 @PATH("/postdata")
 @MediaType.Apllication_JSON
 public int postData(@PathParam("datalist") List<String> datalist){
 return 0;
 }

 var myApp=Angular.module('App',[]);
 myApp.controller('myCTRL',function($http,$scope){
 $http({
 method : 'POST',
 hearders : {
'Content-Type' : 'application/json; charset=utf-8',
'Accept' : 'application/json'
},
param : <new code i want here for the corresponding rest controller>
})
});

请注意:字符串列表将来自一个 json 文件,我通过使用 $http 检索 json 文件并存储在 $scope 变量中完成了该部分。

我想将此 $scope 变量转换为列表并发送列表数据。

【问题讨论】:

    标签: java angularjs html rest


    【解决方案1】:

    您可以像这样执行 POST 请求:

    const options = {
        headers: ...
    };
    
    const postBody = {
        yourParam: [ 'string', 'string' ]
    };
    
    $http.post('url', postBody, options);
    

    【讨论】:

      猜你喜欢
      • 2016-03-22
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 2019-09-10
      • 1970-01-01
      • 2021-05-17
      • 2020-08-23
      • 1970-01-01
      相关资源
      最近更新 更多