In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to use @ PathVariable annotation to achieve dynamic value transfer", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to use @ PathVariable annotations to dynamically pass values".
@ PathVariable annotation to realize dynamic value transfer
Dynamic value transfer
@ RequestMapping (value= "/ Test/ {id}") public void Test (@ PathVariable Integer id) {.}
Usage
In the action of the page form, write the corresponding method name in controller
TestController.java@RequestMapping (value= "/ {methodName}") public String TZ (@ PathVariable String methodName) {return methodName;} dynamic parameters are resolved using @ PathVariable
Now there is a hyperlink as follows
${article.title}
The feature of this hyperlink is that the id value parsed by the EL expression is added to the URL path.
Therefore, in the Controller layer of SpringMVC, you need to parse it, using @ PathVariable ("articleId") Long articleId to parse.
@ PathVariable is specifically used to parse dynamic parameters in URL requests.
The code in the Controller layer is as follows
Public static final String URL_ARTICLE_READ = "article/readArticle/ {articleId}" / * go to the article details page * according to the article ID number specified in the URL path, get the content of the article * * @ param articleId the ID number of the article specified * @ return to obtain the data of this article And go to the article details page * / @ RequestMapping (value = {URL_ARTICLE_READ}) public ModelAndView readArticle (@ PathVariable ("articleId") Long articleId) {LOGGER.info ("enter article detail page, articleId = {}", articleId) Final Article article = articleService.getArticleById (articleId);.}
In this way, the value of ${article.id} on the page is finally mapped to Long articleId in Java.
At this point, I believe you have a deeper understanding of "how to use @ PathVariable annotations to achieve dynamic value transfer". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.