我无法从Java文件中的Angular js中获取JSON数据。错误在哪里?
Store.java
...
@GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE)
public Object getProducts() {
return this.products;
}
...
Main.js
var app = angular.module('myShoppingList', ['ngRoute']);
app.controller('myCtrl', function($scope, $http) {
$http.get('/').
then(function(response) {
var data = response.data;
console.log(data);
});
});
已更新:
我更改了代码。而且我现在没有错误,但仍然无法获得响应。数据
@GetMapping(value = "/products", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<Object> getProducts() {
return new ResponseEntity<>(this.products, HttpStatus.OK);
}
var app = angular.module('myShoppingList', ['ngRoute']);
app.controller('myCtrl', function($scope, $http) {
$http.get('/products').
then(function(response) {
var data = response.data;
console.log(data);
});
});