Spring boot (I) quick start

1、 About spring boot

Before we begin to understand spring boot, we need to understand spring first, because the birth of spring boot is closely related to spring. Spring boot is a product of the development of spring to a certain extent, but it is not a substitute for spring. Spring boot is to make programmers use spring better. Some people may be confused at this point. What is the relationship between spring and spring boot?

1. Development history of spring

Before we begin, let's take a look at spring. The predecessor of spring is interface21. This framework was originally designed to solve the problem of cumbersome and bloated EJB development and provide another simple and practical solution for J2EE. After the official version of spring 1.0 was released in March 2004, it attracted extensive attention and hot comments in the Java industry. Since then, spring has become very popular in the Java industry, He has become a dazzling star in the Java industry all the way. So far, he is irreplaceable. He once became the real standard in J2EE development. His founder rod Johnson also became famous and gained both fame and wealth. Now he is an excellent angel investor and has reached the peak of human life.

2. Birth of spring boot

Since spring is already so excellent, why is there a spring boot?

With the development of spring, spring has gradually changed from a small and sophisticated framework to a broad and comprehensive framework. On the other hand, with the development of new technologies, such as the rise of nodejs, golang and ruby, spring has gradually become cumbersome. A large number of cumbersome XML configurations and third-party integrated configurations have made spring users miserable, At this time, a solution is urgently needed to solve these problems.

At this juncture, spring boot came into being. In 2013, spring boot began research and development. In April 2014, spring boot 1.0 was officially released. At the beginning of its birth, spring boot received extensive attention from the industry. Many individuals and enterprises began to try it one after another. With the release of spring boot 2.0, spring boot was once again brought to the public's attention, More and more large and medium-sized enterprises use spring boot in the formal production environment. It is worth mentioning that spring officials also take spring boot as the primary promotion project and put it in the first place on the official website.

3. Introduction to spring boot

Spring boot is a new framework provided by pivot team. It is designed to simplify the initial construction and development process of spring applications. The framework uses a specific way to configure, so that developers no longer need to define templated configurations. Spring boot is actually a framework that integrates many pluggable components (framework) with embedded tools (such as tomcat, jetty, etc.) to facilitate developers to quickly build and develop.

4. Spring boot features

2、 Development environment

Spring Boot 2.0. four

JDK 1.8

IDE:IntelliJ IDEA 2018.2

Note: spring boot 2 X requires Java 8 and above, and no longer supports Java 6 and Java 7

3、 Development tools

IntelliJ IDEA Vs MyEclipse

The choice of development tools is what everyone should experience and choose. If you are an old hand, you can ignore this section.

Once upon a time, eclipse and MyEclipse dominated Java users, but now, year after year, it's impolite to say that I didn't feel any change from MyEclipse 6.0 ten years ago to MyEclipse 2017 now. I still have the same skin, the same layout and the same feeling of taking off and using cards. Even after optimizing a bunch of configurations according to Google's guidelines, You'll also find little effect.

This reminds me of Nokia, which was once brilliant for a time. Up to now, it still doesn't know what it has done wrong, but times have changed. When a thing can't keep up with the pace of changes of the times, it will be replaced by something new and more suitable. I have to say that I used to be a loyal lover of MyEclipse, and once a person accepts something, it is usually difficult to change it out of habit.

However, today, I have to admit that IntelliJ idea is much better than MyEclipse in terms of appearance and running speed, especially in terms of support for spring boot. Therefore, IntelliJ idea is the best choice.

4、 Spring boot version number Description

The version selection of spring boot is generally as follows:

What does the English after the version number mean?

The specific meaning is shown below:

5、 Spring boot project creation

There are two ways to create a spring boot project:

Note: according to the "development tools" chapter above, using idea is the most suitable language for spring boot development, so all contents in this section are completed using idea.

Method 1: visit the website to create a project

Method 2: create using idea spring initializr (recommended)

Click file = > New = > Project = > select spring initializr and press the boot operation, as shown in the following figure:

The final project directory is shown as follows:

Catalog description

As shown in the figure above, the directory division of the whole project is quite clear, and several important files need to be mentioned separately:

6、 Project operation

For the convenience of demonstration, we are in hellospprinbootapplication Java directly adds an access method index, returns a hello information, and right-click run to run the project.

be careful:

Use advanced

If we need to pass parameters and return data in JSON format, we should do this: repeat the operation in the previous step and annotate the class with @ restcontroller to return information in JSON format. If there are parameters, directly add the parameter name to the method. The parameter name of the method and the URL parameter name must be the same one-to-one correspondence, otherwise the obtained parameter value is null, As shown in the figure:

Summary: as shown in the figure, the transfer order of parameters is irrelevant and does not affect the value.

7、 Hot deployment

According to the above tips, we have completed the creation and operation of the spring boot project, but there is a problem that we need to restart debugging every time we modify the code to make the code take effect. It's troublesome. Is there a simple way?

The answer is yes. That's the hot deployment.

The configuration of hot deployment is as follows:

Step 1: set idea to enable automatic project compilation

File = > Settings = > build, execute, deployment = > build project automatically on the right side of the compiler

As shown below:

Step 2: enable automatic generation when the project is running

CTRL + Shift + a (Windows system), command + Shift + Alt + / (MAC system)

Search command: Registry = > check compiler automake. allow. when. app. running

As shown below:

The final effect is shown in the figure below:

8、 Summary

Pick it up, scan and join the circle

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>