【微服务架构 - 07 - Spring Boot】01 第一个 Spring Boot 应用程序

概述


使用 Intellij IDEA 来新建一个 Spring Boot 项目。

打开 IDEA -> New Project -> Spring Initializr

在这里插入图片描述

填写项目信息

在这里插入图片描述

选择 Spring Boot 版本及 Web 开发所需的依赖

在这里插入图片描述

保存项目到指定目录

在这里插入图片描述

工程目录结构

创建完成后的工程目录结构如下:

在这里插入图片描述

  • .gitgnore: Git 过滤配置文件
  • pom.xml: Maven 的依赖管理配置文件
  • HelloSpringBootApplication.java: 程序入口
  • resources: 资源文件目录
    • static: 静态资源文件目录
    • templates: 模板资源文件目录
    • application.properties: Spring Boot 的配置文件,实际开发中会替换成 YAML 语言配置(application.yml)

功能演示


创建一个 Controller 来演示一下 Spring Boot 的神奇功能

package com.yuu.hello.spring.boot.controller;

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

/**
 * @Classname HelloController
 * @Date 2019/1/27 12:27
 * @Created by Yuu
 */
@RestController
public class HelloController {

    @RequestMapping(value = "", method = RequestMethod.GET)
    public String sayHi() {
        return "Hello Spring Boot";
    }
}

启动 HelloSpringBootApplication 的 main() 方法,浏览器访问 http://localhost:8080 可以看到:

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_37581282/article/details/86665070
今日推荐