Javascript 如何从返回JSON的RESTWeb服务加载ng表中的数据
我想从在SpringMVC中返回REST web服务的JSON加载我的表,但是我得到了以下错误,即我的REST方法不支持get方法 我的控制器映射的URL就是这个Javascript 如何从返回JSON的RESTWeb服务加载ng表中的数据,javascript,angularjs,spring-mvc,angular-resource,ngtable,Javascript,Angularjs,Spring Mvc,Angular Resource,Ngtable,我想从在SpringMVC中返回REST web服务的JSON加载我的表,但是我得到了以下错误,即我的REST方法不支持get方法 我的控制器映射的URL就是这个 http://localhost:8080/MyApp/doc/showDocTable/ URL会从这个变为这个 http://localhost:8080/MyApp/doc/showDocTable/?count=10&page=1 我不知道为什么URL会变成这样,因为我只是在做网站上的基本示例 下面是我的控制器中调
http://localhost:8080/MyApp/doc/showDocTable/
URL会从这个变为这个
http://localhost:8080/MyApp/doc/showDocTable/?count=10&page=1
我不知道为什么URL会变成这样,因为我只是在做网站上的基本示例
下面是我的控制器中调用webservices的函数
var Api = $resource('http://localhost:8080/MyApp/doc/showDocTable/');
this.tableParams = new NgTableParams({}, {
getData: function (params) {
// ajax request to api
return Api.get(params.url()).$promise.then(function (data) {
params.total(data.inlineCount); // recal. page nav controls
return data.results;
});
}
});
这是我在SpringMVC中的控制器方法
@RequestMapping(value = "/doc/showDocTable/", method = RequestMethod.GET)
public ResponseEntity<List<HistDoc>> showTable() {
List<HistDoc> listHistDoc = docDAO.getDocs();
return new ResponseEntity<List<HistDoc>>(listaHistDoc, HttpStatus.OK);
}
这里是我控制台中的错误
WARN 2016-08-11 12:46:58,206 [http-listener-1(4)] org.springframework.web.servlet.PageNotFound - Request method 'GET' not supported
我认为问题在于,ngTable不知何故将URL更改为那个奇怪的URL,而我在Spring中的web方法不知道该做什么
编辑1
我从后端方法url中删除了“/”,如下所示“@RequestMapping(value=“/doc/showDocTable”,method=RequestMethod.GET)
公共响应性>可展示性(){
List listHistDoc=docDAO.getDocs()
但现在我在浏览器firefox控制台中遇到了这个错误
Error: $resource:badcfg
Response does not match configured parameter
Error in resource configuration for action `get`. Expected response to contain an object but got an array (Request: GET http://localhost:8080/MyApp/doc/showDocTable)
编辑2:
这是我的HTML
<div class="col-lg-12" ng-controller="EstHistDoc as demo">
<table ng-table="demo.tableParams" class="table table-bordered table-striped table-condensed">
<tr ng-repeat="row in $data track by row.idDoc">
<td data-title="'Name'" filter="{name: 'text'}" sortable="'name'">{{row.name}}</td>
<td data-title="'Description'" filter="{description: 'text'}" sortable="'description'">{{row.description}}</td>
</tr>
</table>
使用Api.query(…)
而不是使用Api.get()
可以解决您的错误:
操作get
的资源配置出错。预期响应为
包含对象但获得数组(请求:GET
)
使用Api.query(…)
而不是使用Api.get()
可以解决您的错误:
操作get
的资源配置出错。预期响应为
包含对象但获得数组(请求:GET
)
必须使用
$resource.query()
(Api.query()
)而不是$resource.get()
(Api.get()
)。必须使用$resource.query()
(Api.query()
)而不是$resource.get()
(Api.get()
).URL没有问题,因为它只添加了查询参数。你能用postman或Advanced Rest Client(Chrome插件)这样的应用程序测试相同的URL吗?你在开发者工具中看到json响应了吗?URL很好,因为我已经对该方法进行了单元测试,如果我访问了该URL()我得到的JSON响应很好,我用firebug测试了它,而且我已经使用了该URL,但使用了另一个表插件(AngularDataTables)我可以加载带有该URL的表,但是我现在想使用ngTable,但是我得到了一个错误。你能在后端调试/记录请求的URL吗?我想我对查询参数的看法是错误的,因为它们可能是问题所在。但是我相信你的后端不支持查询参数,因此无法识别端点。试着看看调用了e right方法。如果没有调用,则尝试将参数添加到$resource(url,{page:'@page',count:'@count'})你指的是什么URL?带参数的那个,因为当我尝试访问这个URLhttp://localhost:8080/MyApp/doc/showDocTable/?count=10&page=1
在我的后台控制台中,我在控制台中得到的带有参数的错误警告2016-08-11 12:46:58206[http-listener-1(4)]org.springframework.web.servlet.PageNotFound-请求方法“GET”不受支持
对不起,是的,我确实引用了该方法。如果删除尾部斜杠会怎么样?如下图所示:http://localhost:8080/MyApp/doc/showDocTable?count=10&page=1
后端可以使用它吗?URL没有问题,因为它只添加查询参数。你能用postman或Advanced Rest Client(Chrome插件)这样的应用程序测试相同的URL吗?你能在开发者工具中看到json响应吗?URL很好,因为我已经对该方法进行了单元测试,如果我访问该URL()我得到的JSON响应很好,我用firebug测试了它,而且我已经使用了该URL,但使用了另一个表插件(AngularDataTables)我可以加载带有该URL的表,但是我现在想使用ngTable,但是我得到了一个错误。你能在后端调试/记录请求的URL吗?我想我对查询参数的看法是错误的,因为它们可能是问题所在。但是我相信你的后端不支持查询参数,因此无法识别端点。试着看看调用了e right方法。如果没有调用,则尝试将参数添加到$resource(url,{page:'@page',count:'@count'})你指的是什么URL?带参数的那个,因为当我尝试访问这个URLhttp://localhost:8080/MyApp/doc/showDocTable/?count=10&page=1
在我的后台控制台中,我在控制台中得到的带有参数的错误警告2016-08-11 12:46:58206[http-listener-1(4)]org.springframework.web.servlet.PageNotFound-请求方法“GET”不受支持
对不起,是的,我确实引用了该方法。如果删除尾部斜杠会怎么样?如下图所示:http://localhost:8080/MyApp/doc/showDocTable?count=10&page=1
后端是否可以使用它?
var Api = $resource('http://localhost:8080/MyApp/doc/showDocTable');
Error: $resource:badcfg
Response does not match configured parameter
Error in resource configuration for action `get`. Expected response to contain an object but got an array (Request: GET http://localhost:8080/MyApp/doc/showDocTable)
<div class="col-lg-12" ng-controller="EstHistDoc as demo">
<table ng-table="demo.tableParams" class="table table-bordered table-striped table-condensed">
<tr ng-repeat="row in $data track by row.idDoc">
<td data-title="'Name'" filter="{name: 'text'}" sortable="'name'">{{row.name}}</td>
<td data-title="'Description'" filter="{description: 'text'}" sortable="'description'">{{row.description}}</td>
</tr>
</table>
[
{
"idHisReg":null,
"idDoc":1,
"name":doc one,
"description:" "a description"
},
{
"idHisReg":null,
"idDoc":2,
"name": doc two,
"description:" "a seconddescription"
}
]