简体   繁体   English

如何从URL springmvc获取ID

[英]how to get id from url springmvc

Working in application with spring mvc . 使用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); 现在我不知道如何从url中获取此ID以在以下方面使用它:metier.ajouterQuestion(q,IdExam);

You can use the @RequestParam annotation to map a request parameter to a parameter in your request method. 您可以使用@RequestParam批注将请求参数映射到请求方法中的参数。 Read the Spring Framework Reference Documentation Chapter 21 - Web MVC framework and search for: 阅读《 Spring Framework参考文档》第21章-Web MVC框架并搜索:

"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. 实际上,如果您认真学习Spring MVC,则应该阅读(或至少略读)第21章的全部内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM