Spring boot 学习之 Hello World

  • 使用IDE新建maven项目,如果使用eclipse,则选择jar包方式(不选择war包方式)

  • 必须要引入继承springboot-parent包,它帮我们实现了很多jar的依赖管理(这个在<dependencies></dependencies>标签外):

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
      </parent>
  • pom文件导入springboot-web依赖即可,springboot默认集成spring mvc:

        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
  • 以上操作完成后,既可编写HelloWorld测试类:

    package xyz.welog.controller;
    
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RestController;
    
    /**
     *  这是我的第一个Spring boot
     */
    @RestController
    @EnableAutoConfiguration
    public class TestController {
    
        @RequestMapping(value = "/hello",method = RequestMethod.GET)
        public String hello() {
            return "Hello Spring Boot";
        }
    
        public static void main(String[] args){
            // 运行
            SpringApplication.run(TestController.class,args);
        }
    }
    
  • 直接运行main方法,有下图结果则成功,浏览器访问:http://localhost:8080/hello
    这里写图片描述

  • 浏览器访问结果:
    这里写图片描述

    最基本的Springboot完成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值