2

I had a controller that accepted params

@GetMapping(value = "/messages/getReceivedMessage")
public
HttpEntity<ReceivedMessageDTO> getReceivedMessage(
        @ApiParam(value = "The message ID", required = true) @RequestParam Long id
)

and I gets the data using an AngularJS in this way

$http({
        url: '/messages/getReceivedMessage',
        method: "GET",
        params: {
            id: messageId
        }
    })
        .then(function (response) {
            $scope.message = response.data;

            if(response.data.date_of_read === null) {
                setDateOfRead();
            }
        })
        .catch(function () {
            console.log('failed');
        });

but now I have decided to change the REST API address and it will accept path variables

@GetMapping(value = "/received/{id}")
public
HttpEntity<ReceivedMessageDTO> getReceivedMessage(
        @ApiParam(value = "The message ID", required = true) @PathVariable Long id
)

How I can send path variables to controller?

1
  • So is the question adding path variables in urls angularJS? Commented Sep 15, 2017 at 17:36

3 Answers 3

2

I'm not sure what you need but all you have to do is call your endpoint using url like "/received/" + someId

Or in angular like

$http.get('/received/' + someId)

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

0

Pass message id along with URL

http({ url: '/received/' + messageId, method: "GET"}) .then(function (response) { $scope.message = response.data; if(response.data.date_of_read === null) { setDateOfRead(); } }) .catch(function () { console.log('failed'); });

Comments

0

You need to change

$http({
        url: '/messages/getReceivedMessage',
        method: "GET",
        params: {
            id: messageId
        }
    })

to

$http({
        url: '/messages/'+messageId,
        method: "GET"
      })

Since, your parameter value became part of path.

Comments

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.