SpringBoot(1)-HelloWorld program

1 HelloWorld

1.1 Create from IEDA

Insert picture description here
Click next, select an operation,
Insert picture description here
select the installation path of the project
Insert picture description here

1.2 Programming

1 Create the directory structure as shown in the figure
Insert picture description here
2 HelloController.java

package com.zs.helloword.controller;

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

// 本身就是一个spring的组件
@RestController
public class HelloController {
    
    
    // 接口 http://localhost:8080/hello
    @RequestMapping("/hello")
    public String hello() {
    
    
        // 调用业务 接受前端的参数
        return "Hello World";
    }
}

3 Run HellowordApplication.java ( note: the created folder and HellowordApplication.java must be at the same level )

1.3 File introduction

1 application.properties: the core configuration file of springboot, such as

# springboot 核心配置文件
# 更改端口号
#server.port= 8081

2 pom.xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!-- 父依赖 -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.zs</groupId>
    <artifactId>helloword</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>helloword</name>
    <description>Demo project for Spring Boot</description>

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

    <dependencies>
        <!-- web场景启动器 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- springboot单元测试 -->
        <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>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4.2</version>
            </plugin>

        </plugins>
    </build>

</project>

Guess you like

Origin blog.csdn.net/zs18753479279/article/details/112390137