开发环境:

  • jdk版本:JDK8
  • maven版本:maven-3.5.2
  • 开发工具:Itellij IDEA 2017.1

前提条件:已安装以上软件并配置好jdk和maven的环境变量

创建步骤:

  1. 点击坐上角file ---》选择new ---》点击project... 如下图所示:

    Intellij IDEA创建spring-boot项目

  2. 点击左边Spring Initializr ---》 右上角新建jdk(若有则不需要) ---》 点击next 如下图所示:

    Intellij IDEA创建spring-boot项目

  3. 看需求修改下图中的信息后点击next(可以直接使用默认)

    Intellij IDEA创建spring-boot项目

  4. 点击左边的Web ---》 选中中间列的Web ---》 点击next 如下图所示:

    Intellij IDEA创建spring-boot项目

  5. 输入项目名称和保存路径 --- 》点击finish

    Intellij IDEA创建spring-boot项目

  6. 创建的项目如下图所示:

    Intellij IDEA创建spring-boot项目
  7. 创建HelloController类,代码如下所示:

    package com.example.demo.controller;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping("/hello")
    public class HelloController {
    
        @RequestMapping("/say")
        public String sayHello() {
            return "hello world";
        }
    }
  8. 执行DemoApplication中main方法后访问http://localhost:8080/hello/say 页面如下所示:

    Intellij IDEA创建spring-boot项目