用springBoot写一个helloworld以及解析

第一步创建maven项目
第二步导入springboot所需要的依赖以及父项目

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>

    <!-- Add typical dependencies for a web application -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

第三步我们需要标注一个springBoot主程序类

@SpringBootApplication
//这里用注解
public class helloworld {

    public static void main(String[] args) {
        //然后让它跑起来
        SpringApplication.run(helloworld.class,args);
    }
}

第四步写一个controller接受客户端请求

@Controller
public class test {
    @ResponseBody
    @RequestMapping("hello")
    public  String test1(){
        return "hello,word";
    }
}

最后运行,在浏览器输入localhost:8080/hello。结果如下图

在这里插入图片描述
我们在导入依赖时,我们还导入了一个父项目,而导入这个父项目的作用就是让我们在导入依赖时不用写版本号了。通过查看父项目Ctrl+鼠标左键,可看到。
在这里插入图片描述
我们还导入了一个依赖,依赖作用是能够帮助我们省去web模块的依赖,也可以通过Ctrl+鼠标左键 看到。
在这里插入图片描述
这里还有一点就是关于starters,springboot将每一个应用场景封装成了每一个starters,我们只需要引入每一个starters相关场景的依赖,就能够使用了,例如上面的starters-web,就帮我们省去了tomcat以及springMvc的配置。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值