Reputation: 27
$scope.getProjectDetails = function(theId){
$http.get('${pageContext.request.contextPath}/api/project', {params: {theId}})
.then(function(response){
$scope.project = response.data;
});
}
this one generetes:
GET http://localhost:8080/editor-application/api/project?theId=1 404
and spring rest wants:
http://localhost:8080/editor-application/api/project/1
controller:
@GetMapping("/project/{theId}")
public Project getProject(@PathVariable int theId) {
return editorService.getProject(theId);
}
how to make them speak with each other?
Upvotes: 0
Views: 53
Reputation: 16785
You are trying to send a variable as a get parameter but in the back-end you are expecting it as a path variable. There can be two solutions to handle this:
@GetMapping("/project")
public Project getProject(@RequestParam int theId) {
...
}
There are no modifications needed for the AngularJS code.
$http
request to send the variable as a path variable.$http.get('${pageContext.request.contextPath}/api/project/' + theId)
.then(function(response){
...
});
In this case the controller does not need any modifications.
Upvotes: 2