1、springboot之HelloWorld

最基本的,官网copy

创建maven项目

maven中添加

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

创建一个类

@Controller
@EnableAutoConfiguration
public class SampleController {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}

运行该方法

然后浏览器中输入http://localhost:8080/

输出Hello World!说明springboot已经成功启动。

原文地址:https://www.cnblogs.com/gudulijia/p/6728965.html