SpringBoot | 建立項目

環境要求

SpringBoot:2.1.8.RLEASE(截止2019.9.28)java

JDK:JDK1.8及以上web

Spring:5.1.9.RELEASE及以上spring

支持編譯工具以下:bash

編譯工具 版本
Maven 3.3+
Gradle 4.4+

支持的內嵌Servlet容器:app

名稱 Servlet版本
Tomcat 9.0 4.0
Jetty 9.4 3.1
Undertow 2.0 4.0

建立項目

在線建立

使用網站start.spring.io/在線建立項目maven

PS:選擇Maven工程、Java源、JDK版本、打包方式、項目名稱、須要依賴模板等生成項目壓縮文件,解壓後經過IDE工具打開便可。

刪除導入項目自動生成的xxx.iml ,而後刷新下右側maven tab便可 spring-boot

使用Maven建立

目錄結構以下:

添加Pom文件工具

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

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
複製代碼

在src/java目錄下建立包,並建立啓動類FisrtApplication網站

package com.xyz;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class FirstApplication{

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

    @RequestMapping("/hello")
    public String Hello() {
        return "hello";
    }
}

複製代碼

啓動項目,訪問:http://localhost:8080/hello,返回ui

此時:目錄結構以下:

使用IDEA工具建立

點擊File-->New-->Project

相關文章
相關標籤/搜索