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

相关文章
相关标签/搜索