无法弄清楚如何获取JSON数据

时间:2020-03-29 22:14:44

标签: java json angularjs

我无法从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);
        });
}); 

enter image description here

已更新:

我更改了代码。而且我现在没有错误,但仍然无法获得响应。数据

@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);
        });
}); 

0 个答案:

没有答案