我想从JSON中加载我的表,该JSON返回SpringMVC中的我的REST Web服务,但是我得到以下错误,说我的休息方法doesn' t支持GET方法。如何从返回JSON的REST Web服务加载表中的数据
我控制器已映射的URL是从这个
http://localhost:8080/MyApp/doc/showDocTable/
和URL更改此
http://localhost:8080/MyApp/doc/showDocTable/?count=10&page=1
我不知道为什么URL变化,因为我” m只是从网站的基本示例http://ng-table.com/#/loading/demo-external-array
这是我的控制器中调用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;
});
}
});
这里是在Spring MVC
@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);
}
我控制器的方法在这里是我得到了我的浏览器
GET XHR http://localhost:8080/MyApp/doc/showDocTable/?count=10&page=1 [HTTP/1.1 405 Request method 'GET' not supported 6ms]
,并在这里的错误在我的控制台错误
WARN 2016-08-11 12:46:58,206 [http-listener-1(4)] org.springframework.web.servlet.PageNotFound - Request method 'GET' not supported
我认为问题在于,ngTable以某种方式改变t他到那个怪异的URL的网址和我在Spring中的web方法不知道该怎么做。
EDIT 1 从我的后端方法的url去掉了 “/” 像这样`@RequestMapping(值= “/ DOC/showDocTable”,方法= RequestMethod.GET) 公共ResponseEntity> showTable() {list} ListHistDoc = docDAO.getDocs();
return new ResponseEntity<List<HistDoc>>(listaHistDoc, HttpStatus.OK);
}`
而且我删除了 “/” 从angularJs控制器GetData方法
var Api = $resource('http://localhost:8080/MyApp/doc/showDocTable');
但现在我得到这个错误在我的浏览器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)
EDIT 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>
,这里是我从后端
[
{
"idHisReg":null,
"idDoc":1,
"name":doc one,
"description:" "a description"
},
{
"idHisReg":null,
"idDoc":2,
"name": doc two,
"description:" "a seconddescription"
}
]
这不是URL的问题,因为它只添加查询参数。您可以使用邮递员或高级休息客户端(Chrome插件)等应用程序测试相同的URL吗?你看到Developer工具中的json响应吗? – Skaparate
URL是好的,因为我已经做了单元测试该方法,如果我访问该URL(http:// localhost:8080/MyApp/doc/showDocTable /)我得到的JSON响应就好了我用萤火虫测试它,我也已经使用该URL,但与另一个表插件(angular-datatables),我能够加载该表与该URL,但我想现在使用ngTable,但我得到该错误 –
你可以调试/记录所请求的网址后端?我认为我对查询参数错了,因为它们可能是问题所在。但我相信你的后端不支持查询参数,因此不能识别端点。尝试查看是否调用了正确的方法。如果不是,则尝试将参数添加到$ resource(url,{page:'@page',count:'@count'}) – Skaparate