0

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.

2 Answers 2

1

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);
}
Sign up to request clarification or add additional context in comments.

Comments

0

Check your PathVariable import. It should be

org.springframework.web.bind.annotation.PathVariable

but not

org.springframework.messaging.handler.annotation.PathVariable

1 Comment

import is org.springframework.web.bind.annotation.PathVariable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.