Controller
java
package com.martin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Component
@RestController
@RequestMapping("employee")
public class EmployeeController {
public final EmployeeRepository employeeRepository;
@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired
public EmployeeController(EmployeeRepository employeeRepository) {
this.employeeRepository = employeeRepository;
}
@GetMapping
public Iterable<Employeer> getTalks() {
return employeeRepository.findAll();
}
}
Plik html z angularem
html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ziom</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="people">
<table>
<tr ng-repeat="x in names">
<td>{{ x.firstName }}</td>
<td>{{x.salary}}</td>
</tr>
</table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('people', function($scope, $http) {
$http.get('http://localhost:8080/employee/')
.success(function (response) {$scope.names =response;});
});
</script>
</body>
</html>
plik html z takimi samymi jsonami co na powyższym zdjęciu
html
[
{
"id": 1,
"salary": 0,
"firstName": null,
"lastName": null,
"address": null,
"phones": []
},
{
"id": 2,
"salary": 500,
"firstName": "Jan",
"lastName": "Sobieski",
"address": null,
"phones": []
},
{
"id": 3,
"salary": 500,
"firstName": "Jan",
"lastName": "Sobieski",
"address": null,
"phones": []
},
{
"id": 4,
"salary": 0,
"firstName": null,
"lastName": null,
"address": null,
"phones": []
}
]
Witam, nie wiem co jest nie tak z tym moim controllerem...
Jak w angularze mam " $http.get('http://localhost:8080/employee/')"
to nic się nie dzieje, brak reakcji ( jakby adres zły był [ bo pewnie jest ] )
a jak wpisze cokolwiek innego w $http.get('.....') czy to będzie ten plik html z danymi, lub jaki kolwiek inny z internetu adres http z jsonami to wszystko się dobrze wyświetla