创建一个SpringBoot项目的两种方式 | SpringBoot系列(一)

1,490 阅读1分钟

拓展

SpringBoot系列学习汇总和拓展

关注收藏不迷路哦~~

一、官网构建(学习用,不推荐使用)
  • 构建地址:点击跳转 在这里插入图片描述

  • 可以根据自己的要求来修改,推荐如下: 在这里插入图片描述

  • 点击构建 在这里插入图片描述

  • 下载后解压 在这里插入图片描述

  • 打开项目 在这里插入图片描述

  • 等待maven下载相关jar包,需要一定的时间,跟你的网速有关 在这里插入图片描述

  • 下载完成是这么个目录结构 在这里插入图片描述

  • 可删除多余文件 在这里插入图片描述

  • 推荐使用yml配置文件并设置启动的端口号,默认为8080 在这里插入图片描述

  • 编写测试接口

  • 在pom中添加web启动器

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
  • 测试代码如下:
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class helloWorldController {

    @RequestMapping(value = "test",method = RequestMethod.GET)
    public String hello(){
        return "hello world!";
    }
}

  • 启动项目: 在这里插入图片描述
  • 浏览器访问,成功! 在这里插入图片描述
一、IDEA构建(推荐方式)
  • 新建项目 在这里插入图片描述

  • 设置项目,不在解释,跟第一种方式一致 在这里插入图片描述

  • 选择组件,测试用,我们只勾选web组件,其他的根据需要自行选择,或者可以进去后在maven中导入也一样 在这里插入图片描述

  • 点击完成 在这里插入图片描述

  • 测试成功 在这里插入图片描述

路漫漫其修远兮,吾必将上下求索~ 如果你认为i博主写的不错!写作不易,请点赞、关注、评论给博主一个鼓励吧~转载请注明出处哦~