【问题标题】:Calling REST API with parameter使用参数调用 REST API
【发布时间】:2018-03-23 17:07:53
【问题描述】:

我正在尝试创建产品浏览器。我编写了带有文本字段、按钮和结果列表的简单 HTML 视图代码。我还使用通过 ID 查询对象的参数编写了 REST API GET 方法。我的视图的 URL 是 #/Products 但 REST 方法 URL #/Products/Id

休息获取

@Path("/{id:[0-9][0-9]*}")
    @Produces("application/json")
    public Response findById(@PathParam("id") Long id) {body}.

现在我正在尝试将控制器写入 #/Product 视图

 angular.module('searchingPage').controller('SearchProductsController', function($scope, $http, $filter, ProductResource ) {

 $scope.search={};
 $scope.performSearchById = function() {
//goal $scope.searchResults = ProductResource.findById($scope.search.id);

    };
})

我怎样才能调用我的 REST API 参数和正确的路径在它的 ID?

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    '#' 符号用于客户端而不是服务器端,你的 rest 方法 url 可能类似于 "api/Products/Id"。你可以简单地调用下面的rest方法

    $scope.performSearchById = function() {
    
        $http({
        url: 'api/Products/' + $scope.search.id,
        method: 'GET'
        }).then(function(data){
                $scope.searchResults = data.data;
               })
        };
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-28
      相关资源
      最近更新 更多