This is the NTH day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021

A program

I’m saying too much. The picture above is the most intuitive

Choose the dependencies we need, in web and SQL

The directory index after creation

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) public class SpringBootDemoApplication { public static void main(String[] args) { SpringApplication.run(SpringBootDemoApplication.class, args); }}Copy the code

This class is equivalent to our code entry, we will be having @ SpringBootApplication add exclude = DataSourceAutoConfiguration. Class attribute, because we initially chose SQL, Or you can just choose Web and not have this problem.

We are creating the Controller package!! Remember SpringBootDemoApplication must over the other classes.

@Controller public class HelloDemo { @ResponseBody @RequestMapping("/Hello") public String HelloDome(){ return "Hello World"; }}Copy the code

I’ll do the same thing with Spring, and then we start the project,

To understand

pom

We did not configure Tomcat and used Tomcat built into SpringBoot.

Next, let’s look at SpringBoot, starting with poM files

Manage all dependent versions of Spring Boot applications. Spring Boot version arbitration center;

By default, we don’t need to write versions to import dependencies; (Dependencies that are not managed in Dependencies naturally require version declarations.)

Spring – the boot – starter – web:

Spring-boot-starter: indicates an initiator in the spring-boot scenario. Helps us import the components that the Web module depends on to run properly;

Spring Boot extracts all of the functional scenarios into one specific starter, simply by introducing all of the dependencies related to those starter scenarios into the project. Import the scenario initiator for the function you want to use

@SpringBootApplication

The SpringBoot application annotation indicates on a class that this class is the main configuration class of SpringBoot, and SpringBoot should run the main method of this class to start the SpringBoot application.

@ SpringBootConfiguration: Spring Boot configuration class;

Marked on a class to indicate that this is a Spring Boot configuration class;

@configuration: The Configuration class annotates this annotation;

Configuration —– configuration file; The configuration class is also a component in the container; @Component

@enableAutoConfiguration: Enables the automatic configuration function.

Spring Boot automatically configured things we needed to configure before; @enableAutoConfiguration tells SpringBoot to enable automatic configuration. In this way, automatic configuration takes effect.

Under the @ EnableAutoConfiguration

@autoConfigurationPackage: Automatic configuration package

@ Import (AutoConfigurationPackages. The Registrar. The class) :

Spring’s underlying annotation @import imports a component into the container; The imported components by AutoConfigurationPackages. The Registrar. The class;

Scan the package of the main configuration class (annotated by @SpringBootApplication) and all components in the following subpackages into the Spring container;

The configuration file

  • Static: Saves all static resources. Js, CSS images;
  • Templates: Saves all the template pages (The default Jar package of Spring Boot uses embedded Tomcat, which does not support JSP pages by default); You can use template engines (Freemarker, Thymeleaf);
  • Application. properties: Configuration file for the Spring Boot application. You can modify some default Settings;

YAML

K :(space)v: indicates a pair of key-value pairs (Spaces must exist).

Control hierarchy with space indented; All left-aligned columns are of the same level

server:
    port: 8081
    path: /hello
Copy the code

K: V: write it literally;

Strings do not use single or double quotation marks by default.

“” : double quotation marks; Does not escape special characters inside the string; Special characters act as their intended meaning

Name: “zhangsan \n lisi” : output; Zhangsan newline lisi

“: single quotation mark; Special characters are escaped, and the special characters end up just plain string data

Name: ‘zhangsan \n lisi’ : output; zhangsan \n lisi

Objects (properties and values), Maps (key-value pairs)

Friends: {lastName: zhangsan,age: 18}Copy the code

Array (List, Set)

Pets: -cat,dog,pigCopy the code