Day1-SpringBoot入门体验

SpringBoot创建第一个HelloWorld程序

一个字 爽 感觉之前学的都是为了学SpringBoot做铺垫了 配置文件一大堆 现在 简直舒服死了 话不多说 直接上图 上代码了

https://abc.flya.top/img/218

  • 首先依旧是 创建一个Maven应用 在pom.xml文件里加入Springboot启动依赖
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
    </parent>
    <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <!--web场景启动器-->
            </dependency>
    </dependencies>

这个启动器包含了一堆jar包 包含之前 Springmvc 等一系列jar包 甚至包含Tomcat!! wc

https://abc.flya.top/img/219

  • 创建主程序 启动入口
package com.fl;

import org.springframework.boot.SpringApplication;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: 风离
 * @Date: 2021/07/10/1:25
 * @Description:
 * 主程序类
 */
@org.springframework.boot.autoconfigure.SpringBootApplication
public class SpringBootApplicationTest {
    public static void main(String[] args) {
        SpringApplication.run((SpringBootApplicationTest.class),args);
    }
}

  • 创建controller层 helloworld案例
package com.fl.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: 风离
 * @Date: 2021/07/10/1:30
 * @Description:
 */

@RestController  // 等价于 @Controller + @ResponseBody 目前~
public class HelloController {

    @RequestMapping("/hello")
    public String hello()
    {
        return "hello ,SpringBoot!!!";
    }
}

这样就能跑起来了??? 确实 离谱的一批 就是这么简单直接

  • 固定名称Application.properties SpringBoot的主配置文件 来进行配置端口号 以及数据库账号密码等~

https://abc.flya.top/img/220

你好 SpringBoot !

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值