Problem polega na tym, że gdy przez kontroler AngularJS pobieram dane z linku http://rest-service.guides.spring.io/greeting
(link z dokumentacji Springa, wystawia po prostu JSONa z polami ID i content) wszystko działa i wyświetla się jak powinno (The ID is 1
), gdy chce odebrać zasoby ze swojego linku http://localhost:8080/greeting
nie wyświetla się nic (The ID is
- i to wszystko). Proszę o jakąś wskazówkę.
@RestController
public class EmpController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(required=false, defaultValue="World") String name) {
System.out.println("==== in greeting ====");
return new Greeting(counter.incrementAndGet(), String.format(template, name));
}
}
public class Greeting {
private final long id;
private final String content;
public Greeting() {
this.id = -1;
this.content = "";
}
public Greeting(long id, String content) {
this.id = id;
this.content = content;
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
}
<!doctype html>
<html ng-app="demo">
<head>
<title>Hello AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
<script src="hello.js"></script>
</head>
<body>
<div ng-controller="Hello">
<p>The ID is {{greeting.id}}</p>
<p>The content is {{greeting.content}}</p>
</div>
</body>
</html>
angular.module('demo', [])
.controller('Hello', function($scope, $http) {
$http.get('http://localhost:8080/greeting').
success(function(response) {
$scope.greeting = response;
});
});