170620、springboot编程之页面版Hello World

书接上回,把Hello World 在页面上显示!

1、在pom文件中加入web支持

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

注意:加入spring-boot-starter-web就可以把spring-boot-starter删除了,spring-boot-starter-web已经包含spring-boot-starter

最终效果:

2、创建报名com.rick.apps.controller,创建HelloController.java编写代码

@RestController
public class HelloController {

    @RequestMapping("/")
    public String hello(){
        return "Hello World!";
    }
}

3、启动项目

到主函数直接run 即可

4、访问页面http://localhost:8080/hello

5、项目结构图

原文地址:https://www.cnblogs.com/zrbfree/p/7403368.html