Angularjs$资源url路径

Angularjs$资源url路径,angularjs,service,resteasy,Angularjs,Service,Resteasy,这是我第一次尝试用参数向url传递方法,但遇到了一些问题。所以从本质上讲,我通过控制器和服务将字符串值从html页面传递到服务器(我使用的是restEasy框架),但我一直得到404 not found错误 所以代码如下 调用控制器的html代码段: <div class="container"> <a href="#notificationGroup" class="btn btn-success" role="button">Create New Distributi

这是我第一次尝试用参数向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}
    });
}); 

希望有帮助。

仔细检查您的
$resource
路径。似乎缺少
:code
参数。是的,我也意识到了这一点。但这可能是什么原因造成的呢?我现在所做的不是传递参数的正确方法吗?您没有在工厂声明
:code
参数。另外,
:name
参数丢失。您在哪里分配的?您的意思是在{name:'@name',code:'@code'}旁边,我需要在工厂中声明代码和名称吗?对不起,我对这个很陌生。你能给我举个例子吗?谢谢你的回答。在我更改代码后,它给出了以下错误:TypeError:Object.keys在非Object上调用