Reputation: 41
I am trying to pass values to spring controller via URL. On angluar side i use location service to change URL:
$location.path('/somePage/' + data.id);
After that controller for somePage triggers:
$routeProvider.when('/somePage/:id'
That controller has a method which needs to fetch data from spring:
$scope.item = Service.findById($routeParams.id);
findById is in essence a http get:
findById: function() {
return $http.get('/something/data/id');
}
On spring side i have a controller:
@RestController
@RequestMapping("/something/data")
public class Controller {
@RequestMapping(value = "/{id}")
public Data findById(@PathVariable Long id) {
return repository.findById(id);
}
}
I can not get spring to fetch id parameter from URL. I am new to angularjs and spring so any suggestions would be much appreciated.
Upvotes: 0
Views: 1508
Reputation: 3104
Where do you pass the id to the method findById? Shouldn't it look like that?
findById: function(id) {
return $http.get('/something/data/' +id);
}
Upvotes: 1
Reputation: 1223
Check your PathVariable import. It should be
org.springframework.web.bind.annotation.PathVariable
but not
org.springframework.messaging.handler.annotation.PathVariable
Upvotes: 0