Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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);
}
share|improve this answer
    
thank you, that was the problem –  user2889669 Dec 29 '13 at 12:08

Check your PathVariable import. It should be

org.springframework.web.bind.annotation.PathVariable

but not

org.springframework.messaging.handler.annotation.PathVariable
share|improve this answer
    
import is org.springframework.web.bind.annotation.PathVariable –  user2889669 Dec 29 '13 at 12:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.