spring boot-2.Hello world

由于 个人习惯,我选择使用STS来作为开发工具。跳过手动构建spring boot 项目的环节,直接使用向导创建spring boot 项目。

1.创建spring boot项目

File ---->New--->Spring Starter Project

填写好项目名称项目坐标,点击Finish即可。项目的路径如下图所示:

右击项目名称,run as --->spring boot app 即可运行项目。

然后我们新建controller 包,新建helloworldcontroller.java 

在helloworldcontroller.java 中编写代码

package com.springboot.controller;

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

@Controller
public class helloworldcontroller {
    
    @ResponseBody
    @RequestMapping("/hello")
    public String helloworld() {
        return "Hello World";
    }
}

重启服务,在浏览器中请求hello,即可得到如下界面

至此,一个简单的spring boot 应用就快速搭建完成。接下来我们来结合文档深入查看其中的原理。

原文地址:https://www.cnblogs.com/li-zhi-long/p/9455596.html