spring boot入门案例

概述

  • 什么是 spring boot ?
    • 用来简化新Spring应用的初始搭建以及开发过程
  • 特点:
    • 维护依赖,解决jar冲突。提供众多启动器 ....-starter (相当于jar包集合)
    • 简化配置,大大减少了配置文件、配置类。
    • 默认实现,默认情况下,提供了众多解决方案。

入门案例:手动搭建

分析

  • 创建maven项目
  • 在pom.xml文件,添加 web开发启动器
  • 编写controller,基于RESTFul
  • 编写启动类

实施

  • 创建maven项目:spring_boot_hello

  • 在pom.xml文件,添加 web开发启动器

        <!--确定spring boot版本-->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.2.5.RELEASE</version>
            <relativePath/>
        </parent>
    
        <dependencies>
            <!--web开发启动器-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
        </dependencies>
    
  • 编写controller,基于RESTFul

    package com.czxy.boot.controller;
    
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    
    @RestController
    @RequestMapping("/hello")
    public class HelloController {
    
        @GetMapping
        public String hello() {
            return "你好";
        }
    }
    
    
  • 编写启动类

    package com.czxy.boot;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class HelloApplication {
        public static void main(String[] args) {
            SpringApplication.run(HelloApplication.class, args);
        }
    }
    
    

访问 在这里插入图片描述

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值