SpringBoot项目创建的三种方式


1 通过官网创建

进入官网,https://start.spring.io/ ,填写信息后点击GENERATE

2 通过IDEA脚手架创建

2.1 IDEA新建项目

选择Spring Initializr ,确认sdk的版本,url地址选择默认的spring官网地址,点击Next

2.2 起Group名字,选择Java版本,点击Next

2.3 选择Web依赖,选择Spring Web,确认Spring Boot版本,点击Next

2.4 起Project name,选择位置,点击Finish

3 通过创建MAVEN工程创建

3.1 创建空白maven项目

3.2 添加(修改)pom依赖

<?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>

    <!--添加父工程依赖-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.3.RELEASE</version>
        <relativePath/>
    </parent>

    <groupId>com.zjw</groupId>
    <artifactId>springbootdemo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!--添加Java版本-->
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <!--添加spring-boot-starter依赖-->
    <dependencies>
        <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>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <!--添加spring-boot打包插件-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

3.3 添加启动器类

package com.zjw;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

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

}

3.4 添加controller类

package com.zjw.controller;

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

@RestController
public class HelloController {

    @RequestMapping("hello")
    public String hello(){
        return "Hello Spring Boot !";
    }
}

3.5 运行Application类的main方法就可以启动SpringBoot项目,访问http://localhost:8080/hello可以看到页面有正常的显示。

posted @ 2020-08-23 11:13  雨中遐想  阅读(2692)  评论(0编辑  收藏  举报