Spring boot quick start

Time:2022-5-27

What is a springboot?

1. Do you need to import many dependencies when developing with SSM?
2. The dependency of introducing SSM is tangled. Is the version compatible?
3. The configuration file is scattered in multiple places, and the modification is cumbersome?
4. Write the basic configuration repeatedly every time you create a new project? Try springboot! This framework is the result of liberal arts and science solving the above problems! Of course, it has more advantages. Let’s have a look!

Second, start with a hello world project

1. Open idea, create a maven project, and select the web app skeleton
2. Improve the directory structure, add folders such as Java resource, and complete the folders of the three-tier architecture (Controller Service Dao / mapper)
3. In POM Add the following content to the XML
<parent>
  <artifactId>spring-boot-starter-parent</artifactId>
  <groupId>org.springframework.boot</groupId>
  <version>2.3.3.RELEASE</version>
</parent>

#If you want to specify the JDK version

<properties>
    <java.version>1.8</java.version?
</properties>

#The following dependency is the official initiator dependency of springboot. In the future, many similar initiators will look like this. Because we specify the parent project above, springboot will automatically help us manage the version without writing the version number of these dependencies

<dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

4. Go back to the Java folder and write the startup class

Write the applicatiton startup class in the Java folder
```

package com.yang;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/*

  • Project entrance
  • */

@SpringBootApplication
public class Application {

public static void main(String[] args) {
    SpringApplication.run(Application.class,args);
}

}

5. Write a hellocontroller in the controller

package com.yang.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloController {

@ResponseBody
@RequestMapping("/hello")
public String Hello (){
    return "<h1>Hello I Am Yang </h1>";
}

}

6. Just run it in the application class
    Enter localhost: 8080 / hello in the browser
    You can witness miracles