spring boot simple entry case

Spring Boot ::   2.2.7

jdk :1.8

Project Engineering Directory 

1. New construction

     pom.xml file configuration is divided into three parts configuration,

First: introduce parent coordinates

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.7.RELEASE</version>
    </parent>

Step 2: In order for Spring Boot to help us complete various automatic configurations, we must introduce the automatic configuration dependencies provided by Spring Boot, which we call starters. Because we are a web project, here we introduce the web starter and add the following dependencies to the pom.xml file

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

Third: Manage jdk version

 If we want to modify the jdk version of the Spring Boot project, we only need to simply add the following properties. If there is no requirement, do not add it.

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

    <!--  配置部分   -->
    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.7.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    <!--  配置部分   -->

   entire file configuration

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>sringboot_demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!--  配置部分   -->
    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.7.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    <!--  配置部分   -->
</project>

2. Create Application class file

package springbootdemo;

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

@SpringBootApplication
public class Application {

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

}

3. Create a Controller file

package springbootdemo.controller;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello(){
        return "hello spring boot";
    }

}

after running

Enter http://localhost:8080/hello in the browser

Guess you like

Origin blog.csdn.net/shi450561200/article/details/131884369