Angularjs $资源 url 路径

Angularjs $resource url path

这是我第一次尝试将带有参数的方法传递给 url 并将 运行 传递给一些问题。所以基本上,我通过控制器和服务将字符串值从 html 页面传递到服务器(我使用的是 restEasy 框架),但我一直收到 404 not found 错误。

于是代码如下

html 调用控制器的代码片段:

<div class="container">
<a href="#notificationGroup" class="btn btn-success" role="button">Create New Distribution List</a>
<div class="panel panel-primary center-block" style="margin-bottom: 10px;margin-top: 10px">
    <div class="panel-heading">
    </div>
    <div id="searchfield">
        <form id="searchFieldForm" autocomplete="on">
            <h4>Code: <input type="text" data-ng-model="code" class="biginput" name="code" >
                Name: <input type="text" name="name" data-ng-model="name"  class="biginput">
                <button data-ng-click="search(name, code)" type="button" class="btn btn-primary">
                    Search</button>
            </h4>
        </form>
    </div>
</div>

控制器:

myApp.controller('SearchController',
function($scope,SearchCollection,$location) {
    $scope.search = function(name, code) {
        $scope.distributionLists = SearchResultCollection.search(name, code);
        $location.path('/list');
    }
});

服务:

myApp.factory('SearchResultCollection', function($resource) {
return $resource('../api/foo/:name/SearchSingle/:code',
    {name:'@name', code:'@code'}, {
        search : {method: 'GET',
            isArray: true}
    })
});

我得到的错误是:

GET http://localhost:9080/api/foo/SearchSingle 404 (Not Found)

有人可以帮我解决这个问题吗?

试试这个代码:

myApp.controller('SearchController',
        function($scope, SearchCollection, $location) {
            $scope.search = function(name, code) {
                $scope.distributionLists = SearchResultCollection.search({name: name, code: code});
                $location.path('/list');
            };
        });

myApp.factory('SearchResultCollection', function($resource) {
    return $resource('../api/foo/:name/SearchSingle/:code', {name: '@name', code: '@code'}, {
        search: {method: 'GET', isArray: true}
    });
}); 

希望对您有所帮助。