Spring Boot-Build the first demo of Spring Boot

Build the first demo of Spring Boot

1. Open the URL provided by Spring's official website: https://start.spring.io/

2. Fill in the required information according to your own requirements

3. Decompress the downloaded file, the file structure is as follows:

4. Import the decompressed project into the IDE (take STS as an example), delete unnecessary files after importing, and finally as follows

The detailed configuration of the pom.xml file is as follows:

<?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>com.xiangty</groupId>
    <artifactId>springboot-starter</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot-starter</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

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

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

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

5. Write HelloController

package com.xiangty.controller;

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

@RestController
public class HelloController {
    @RequestMapping("/hello")
    public Object hello() {
        return "Hello SpringBoot";
    }   
}

6. Start the project

 

7. Enter localhost:8080/hello in the browser

 

Please correct me if there are any errors, thank you.

Guess you like

Origin blog.csdn.net/qq_33369215/article/details/83218237