一分钟搭建Spring Boot

1.首先你的电脑需要安装jdk、Apache Maven、Intellij IDEA

2.新建项目  (敲重点,有的同学有没有Spring Initializr 这个请到本文章后面看安装步骤

3.选择基本条件

 

添加HelloCtrl类

添加如下代码

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller//这是一个控制器
public class HelloCtrl
{
    @RequestMapping("/")//将地址映射到 / 即访问http://localhost:8080 就可以进入这个方法
    @ResponseBody//返回数据,如果不添加该注解将在resources/templates下寻找与之对应的html模版
    public String hello()
    {
        return "hello spring boot";
    }
}

4.测试程序

打开浏览器,http://localhost:8080

出现hello spring boot字样则成功

 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

没有Spring Initializr

1.【file】->【Settings】->【Plugins】

原文地址:https://www.cnblogs.com/PerZhu/p/10708809.html