Getting to know SpringBoot -- SpringBoot Quick Start Nanny-Level Tutorial (1)


foreword

In order to consolidate the knowledge learned, the author tried to start publishing some blogs of learning notes for future review. Of course, it would be great if it could help some newcomers learn new technologies. The author is a piece of food. If there are any mistakes in the records in the article, readers and friends are welcome to criticize and correct.
(The reference source code of the blog can be found in the resources on my homepage. If you have any questions during the learning process, please feel free to ask me in the comment area)

insert image description here

1. Getting to know SpringBoot first

1. Introduction to Spring Boot

  1. Introduction to Spring Boot

Spring Boot is an open source framework provided by the Pivotal team, which simplifies the creation and deployment of spring applications . It provides a wealth of Spring modular support, which can help developers build enterprise-level applications more easily and quickly.

  1. Advantages of SpringBoot over Spring
  • Disadvantages of Spring

1. The configuration is relatively complicated, but annotation configuration was introduced later, which simplifies the configuration process.
2. Dependency management is not implemented, such as controlling the version compatibility relationship between dependencies, which is very troublesome.
3. The logic of the program made by using Spring is not very clear, and the code is not intuitive. You need to check the configuration from time to time to understand the code

  • Advantages of Spring Boot

1. Through the automatic configuration function, the complexity is reduced. At the same time, it supports a variety of open source frameworks based on JVM, which can shorten the development time and make the development easier and more efficient. 2. Avoid a large number of
Maven imports and various version conflicts
. 3. There is no separate The web server is required, which means you no longer need to start the Tomcat server separately.

2. Create SpringBoot project with compiler IDEA

Next, let's develop a simple SpringMVC program through SpringBoot to experience the advantages of SpringBoot and understand how to use the IDEA compiler to create a Spring project initialization

  1. Create a new module, select Spring initialization, and configure basic information about the module

insert image description here

  1. Check the relevant technical dependencies and the version number of SpringBoot

insert image description here

  1. Write the Controller layer (omit the corresponding entity classes and related interfaces, etc.)
@RestController
@RequestMapping("/books")
public class BookController {
    
    

    @GetMapping("/{id}")
    public String getById(@PathVariable Integer id){
    
    
        System.out.println("id ==> "+id);
        return "hello , spring boot!";
    }

}
  1. Example code file structure

insert image description here

  1. DemonApplication startup class running results
  • IDEA running results

insert image description here

  • browser access results

insert image description here

  1. What is the difference in operation between developing SpringMVC with SpringBoot and traditional development?

insert image description here

  • The technology in pom.xml has been checked when creating the project. If the checked technology is enough to meet the project requirements, you can omit writing the technology coordinate configuration file

  • Traditional SprngMVC development needs to create the corresponding Config class separately to configure Web3.0-related properties, but it is not necessary to develop with SpringBoot technology

  • SpringBoot technology has a built-in tomcat server, no manual configuration is required

Reason: A lot of content is encapsulated in pom.xml and startup classes

3. Create a SpringBoot project on the official website

  1. Open the spring official website and check the Projects – Overview option

insert image description here

  1. Select Spring Boot

insert image description here

  1. Find the Quick Create SpringBoot option at the bottom of the page and click

insert image description here

  1. Fill in the relevant information of the project and check the relevant technical dependencies

  1. Click GENERATE (generate), the corresponding compressed package will be generated, decompress and open and compile with the compiler

4. SpringBoot project quick start (basic ability to separate front and back ends)

The SpringBoot program can run quickly without tomcat and compiler, which is convenient for interaction during front-end and back-end development, but front-end personnel are still required to connect to the same database.

  1. Double-click to execute the maven-Lifecycle-package command

insert image description here

  1. Find the generated jar package, enter the control command line cmd in the path bar

insert image description here

  1. After entering the control command window, enter the command line of java - jar d (the initial letter of the project name) after the newly encapsulated jar package path, then click the tab key to complete, and press Enter to run

insert image description here

  1. browser access

insert image description here
insert image description here

  1. Precautions

insert image description here

5. Understand SpringBoot start-up dependencies (pom.xml) and startup classes

  1. A preliminary understanding of SpringBoot's starting dependencies

In the pom file, Artifact IDs are prefixed with spring-boot-starter-, these are all Spring Boot starting dependencies, and they all contribute to the construction of Spring Boot applications.

insert image description here

1.starter:
The common project name in SpringBoot, which defines all project coordinates used by the current project to achieve the purpose of reducing dependency configuration
2.parent:
The project to be inherited by all SpringBoot projects, defines several coordinate version numbers (dependency management, 3.
Actual development:
When using arbitrary coordinates, only write G and A in GAV, and V (version) is provided by SpringBoot.
If a coordinate error occurs, specify the version (be careful about the version conflict)

  1. SpringBoot startup class

insert image description here

1. SpringBoot startup method: startup class (example shown in the figure)
2. SpringBoot uses the jar packaging method when creating a project
3. SpringBoot's boot class is the entry point of the project, and the project can be started by running the main method

  1. Replace the SpringBoot startup server (tomcat --> jetty)
  • Edit the pom.xml file

insert image description here

  • Run the startup class

insert image description here

insert image description here

Summarize

Everyone is welcome to leave a message for exchange and criticism. If the article is helpful to you or you think the author's writing is not bad, you can click to follow, like, and bookmark to support.
(The reference source code of the blog can be found in the resources on my homepage. If you have any questions during the learning process, please feel free to ask me in the comment area)

Guess you like

Origin blog.csdn.net/HHX_01/article/details/130943295