Kaoutar Laz
Kaoutar Laz

Reputation: 81

how to get id from url springmvc

Working in application with spring mvc . I have to add questions for exams. when i choose the exam my link is like this :

     localhost:7070/elearning/expert/ajouterQuestionExam?idExam=1 

now i don't know how to get this id from url to use it in: metier.ajouterQuestion(q,IdExam);

Upvotes: 1

Views: 590

Answers (1)

Stephen C
Stephen C

Reputation: 719259

You can use the @RequestParam annotation to map a request parameter to a parameter in your request method. Read the Spring Framework Reference Documentation Chapter 21 - Web MVC framework and search for:

"Use the @RequestParam annotation to bind request parameters"

for an explanation, including examples. There are probably other ways too.

In fact, if you are serious about learning Spring MVC, you ought to read (or at least, skim read) all of Chapter 21.

Upvotes: 1

Related Questions