In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to build a SpringMVC project", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to build a SpringMVC project" this article.
Why do you want to learn SpringMVC?
Spring framework claims to be an one-stop solution for JavaEE applications. Spring itself provides a well-designed MVC framework, SpringMVC. Because the Spring framework has a high market share, more and more Spring framework users use SpringMVC to replace the former king Struts2 of the MVC framework. Of course, Spring can also seamlessly integrate excellent MVC frameworks such as Struts and JSF.
More and more enterprises begin to choose SpringMVC+Mybatis to build system architecture, and today, when e-commerce is popular, SpringMVC+Mybatis has become the best match for e-commerce project architecture.
What is MVC thought? What are the advantages of MVC? MVC, which is not a unique design idea of Java language, nor a unique idea of Web applications, but a specification that all object-oriented programming languages should follow. The advantages of MVC are:
He divides an application into three levels (there is not much overview of MMagol VMagneC here). These three parts work together to minimize the coupling of the application code, which improves the expansibility and maintainability of the program.
Multiple views can correspond to a model, which reduces the repetition and maintenance of the code.
Because the model data is separated from the display layer, the model data can be applied to any display technology, including jsp pages, velocity templates, or directly generate Excel documents.
MVC is more conducive to engineering management software, different layers perform their own duties, and is conducive to the management of program code through engineering and instrumental methods.
What are the advantages of SpringMVC?
SpringMVC is flexible, non-invasive, and configurable.
SpringMVC provides a front-end controller DispatcherServlet that developers do not need to develop additional controller objects.
SpringMVC has a clear division of labor, including controller, validator, command object, model object, handler mapping attempt parser and so on. A special object is responsible for the implementation of each function.
SpringMVC can automatically bind user input and convert data types correctly. (for example, strings can be parsed to properties of type int or float of the model.)
SpringMVC uses a name / value Map object for more flexible model data transfer.
SpringMVC has a built-in common validator that validates user input and redirects to the input form if the verification fails. Input validation is optional and supports programming and declaration.
SpringMVC supports internationalization and is extremely easy to configure.
SpringMVC supports a variety of view technologies: JSP, Velocity and FreeMarker.
Spring provides a simple and powerful JSP tag library that supports data binding and makes it easier to write JSP pages.
Without saying much, go straight to the code (the steps for writing HelloWorld):
The first thing you need to do is import the required jar packages: all the jar packages for Spring and commons-logging.jar.
Spring download address: http://repo.spring.io/release/org/springframework/spring/.
Commons-logging.jar download address: http:commons.apache.org.
Configure the configuration of the web.xml--DispatcherServlet front-end controller.
Springmvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation / WEB-INF/springmvc-config.xml 1 springmvc /
Configure the implementation of the Controller Controller class of SpringMVC
Public class HelloController implements Controller {private static final Log logger = LogFactory.getLog (HelloController.class); @ Override public ModelAndView handleRequest (HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {/ / TODO Auto-generated method stub logger.info ("handleRequest called"); ModelAndView mv = new ModelAndView (); mv.addObject ("message", "Hello SpringMVC!") Mv.setViewName ("/ WEB-INF/content/welcome.jsp"); return mv;}}
Implementation of View Page
First acquaintance of SpringMVC$ {requestScope.message}
These are all the contents of the article "how to build a SpringMVC Project". 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.