Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use SpringMVC annotations

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to use SpringMVC notes, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

1. Configure the front-end processor SpringMVC_01 springmvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:springmvc.xml springmvc / 2 in the web.xml file, the processor mapper and the processor adapter in the springmvc.xml file View parser 3. Write Handlerpackage com.ys.controller Import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView;// uses the @ Controller annotation to indicate that this class is a Handler@Controllerpublic class HelloController @ RequestMapping ("hello") public ModelAndView hello () {ModelAndView modelView = new ModelAndView () in parentheses of the Handler@Controllerpublic class HelloController {/ / @ RequestMapping comment. / / similar to request.setAttribute () modelView.addObject ("name", "Zhang San"); / / configure the returned view name. Since we have configured prefixes and suffixes in springmvc.xml, we can simply write the view name here as modelView.setViewName ("index"); / / modelView.setViewName ("/ WEB-INF/view/index.jsp"); return modelView;}}

Note the use of @ Controller and @ RequestMapping annotations

4. Write the view index.jspInsert title herehello:$ {name} 5. Type in the browser: http://localhost:8080/SpringMVC_03/hello above is all the content of the article "how to use SpringMVC annotations". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report