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

What is SpringMVC?

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

Share

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

This article mainly shows you "what is SpringMVC", 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 this article "what is SpringMVC?"

I. Overview of SpringMvc

SpringMVC is a WEB layer framework based on MVC design pattern.

SpringMVC design pattern:

MVC, whose full name stands for Model View Controller, is a software design pattern.

Specific meaning:

Model: model, used to process data, is generally an entity class, such as the User class

View: view, used to display the interface, can be JSP or Html

Controller: controller, which determines which interface to display the model; (it is actually a business processor)

The role of SpringMVC in the project:

The JavaEE development specification stipulates that a Java web project should be divided into three layers:

WEB layer: page data display, page jump scheduling

Business layer: business processing and functional logic, transaction control

Persistence layer: data access and encapsulation, dealing with databases

II. Steps for getting started with case development

Environment: jdk1.8 Tomcat8.5 idea2018 manven parent project child module

1. Create a web project and introduce dependencies

Project structure: create what you don't have

Pom.xml depends on adding the packaging method as war

Com.day01springmvc Springmvc01 war org.springframework spring-webmvc org.slf4j slf4j-log4j12 jstl jstl javax.servlet servlet-api Javax.servlet jsp-api org.apache.tomcat.maven tomcat7-maven-plugin 8080 /

Add web.xml files and directories

2. Configure the SpringMvc entry file

-- DispatcherServlet-- is understood as total scheduling and configuration in web.xml

Web.xml

Springmvc org.springframework.web.servlet.DispatcherServlet 1 springmvc /

3. Create a Springmvc.xml file

-- understood as: adapter + view parser

Springmvc.xml

4. Create a business processor Controller class

HelloController.java inherits Controller

Package com.day01springmvc.controller; import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.Controller; import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse; / * Service processor * @ Author: ShaoWei Sun. * @ Date: Created in 20:58 2018-11-16 * / public class HelloController implements Controller {/ * processing requests * / @ Override public ModelAndView handleRequest (HttpServletRequest request HttpServletResponse response) throws Exception {System.out.println ("hello request came in.") ModelAndView mv = new ModelAndView (); / / add a data that can be taken out on the page mv.addObject ("msg", "this is the first springmvc program"); / / set the name of the view mv.setViewName ("hello"); return mv;}}

5. Test

6. Running process

The above is all the content of this article "what is SpringMVC?" 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