使用Spring Boot创建Web应用程序的讨论

在Spring Boot中,Web应用的使用方法是什么来着?

我心想着尝试回忆做法。

GitHub: https://github.com/wataru775/example.springboot.web/tree/0.helloworld
GitHub:https://github.com/wataru775/example.springboot.web/tree/0.helloworld

@Controller
public class RootController {
    @RequestMapping("/")
    @ResponseBody
    public String index() {
        return "Hello World!";
    }
}

只有这么多呢w

然而,定义有点模糊。

POM.xml 是… (POM.xml is…)

<?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.mmpp</groupId>
    <artifactId>example.springboot.web</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>11</java.version>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <spring-boot.version>2.6.2</spring-boot.version>
    </properties>

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

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

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

只需添加库

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

就这样吧。

這是一份備忘錄

順便做个备忘录

在IntelliJ IDEA中,当编写maven的依赖时,要实现反映,可以通过右键单击pom.xml文件然后选择[MAVEN] > [Reload Project],
我对此曾有些困惑。

目标作业:IntelliJ IDEA 2021.3.1

来源:https://www.mmpp.org/archives/2688

bannerAds