spring-boot-starter-web (Web starter)

Spring MVC is a lightweight Web development framework based on the MVC design pattern provided by Spring. It itself is a part of the Spring framework and can be seamlessly integrated with Spring. It has inherent advantages in performance and is the most mainstream Web development in the industry today. one of the frames.

Spring Boot is an open source framework based on Spring, which provides spring-boot-starter-web (Web scene starter) to support Web development. spring-boot-starter-web provides us with an embedded Servlet container and SpringMVC dependencies, and provides a large number of automatic configurations for Spring MVC, which can be applied to most Web development scenarios.
Spring Boot Web Rapid Development
Spring Boot provides automatic configuration for Spring MVC, and adds the following features to the default features of Spring MVC:

Introduced ContentNegotiatingViewResolver and BeanNameViewResolver (view resolver)
support for static resources including WebJars
Automatic registration of Converter, GenericConverter and Formatter (converter and formatter)
support for HttpMessageConverters (used in Spring MVC to convert HTTP requests and responses The message converter)
automatically registers the MessageCodesResolver (used to define error code generation rules)
supports access to the static home page (index.html)
automatically uses ConfigurableWebBindingInitializer

As long as we introduce spring-boot-starter-web in pom.xml in the Spring Boot project, we can directly use Spring MVC for Web development without any configuration.
example

  1. Create a Spring Boot project named spring-boot-springmvc-demo1, and add spring-boot-starter-web dependencies in the dependencies node of its pom.xml, the code is as follows.

    org.springframework.bootspring
    -boot-starter-web

  2. Create a HelloController under the tangyu9880 package, the code is as follows.
    package tangyu9880.controller;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    @Controller
    public class HelloController { @ResponseBody @RequestMapping ("/hello") public String hello() { return "tangyu9880"; } }





  3. Start Spring Boot, and access "http://localhost:8080/hello" in the browser, and the result is as shown in the figure below.
    insert image description here

HelloController
Figure 1: Access to HelloController Result
Note: Since spring-boot-starter-web introduced the core starter spring-boot-starter for us by default, when the pom.xml in the Spring Boot project introduced spring-boot-starter- After the web dependency, there is no need to introduce the dependency of the spring-boot-starter core starter.

Guess you like

Origin blog.csdn.net/weixin_64842782/article/details/125089633