• SpringBoot学习(一)---初识SpringBoot


    SpringBoot简介

    SpringBoot是由Pivotal团队提供的全新框架,其设计目的是用来简化Spring应用的初始搭建以及开发过程

    Springboot入门案例

    1.创建springboot程序

    创建New Module选择Spring Initializr
    在这里插入图片描述
    之后选中web下的Spring Web,点击creat创建springboot程序

    在这里插入图片描述

    2.编写控制器

    BookController类中写了一个方法,获取请求id

    package com.itheima.controller;
    
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping("/books")
    public class BookController {
        @GetMapping("/{id}")
        public String getById(@PathVariable Integer id)
        {
            System.out.println("id为"+id);
            return "Hello,SpringBoot!";
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    springboot内置了tomcat服务器,Application直接运行就可以启动tomcat服务器
    在这里插入图片描述
    用postman发送请求,结果如下:
    在这里插入图片描述

    SpringBoot项目快速启动

    在这里插入图片描述
    在命令窗口下输入启动指令:
    在这里插入图片描述

    SpringBoot起步依赖

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    与web有关的依赖,包括tomcat服务器
    在这里插入图片描述
    与测试有关的依赖,包含了是spring-test
    在这里插入图片描述

    SpringBoot程序启动

    springboot在创建项目时,采用jar的打包方式
    springboot的引导类Application是项目的入口,运行main方法就可以启动项目
    Application类:在这里插入图片描述

    切换Web服务器

    将springboot内置服务器tomcat切换为jetty服务器
    先将tomcat服务器的依赖排除

    
                org.springframework.boot
                spring-boot-starter-web
                
                    
                        org.springframework.boot
                        spring-boot-starter-tomcat
                    
                
            
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    再导入jetty服务器的依赖

    		
                org.springframework.boot
                spring-boot-starter-jetty
            
    
    • 1
    • 2
    • 3
    • 4

    启动项目,点击Application类,右键运行
    在这里插入图片描述

  • 相关阅读:
    929903-87-7,Ac-Arg-Leu-Arg-MCA
    ubuntu22 mysql8.0如何搭建主从复制?[亲自实践,步骤简洁]
    Java总结String类
    Win10下VsCode远程免密连接服务器
    4.验证面试高频问题整理(附答案)
    口碑好的猫罐头有哪些?宠物店受欢迎的5款猫罐头推荐!
    Python的web自动化学习(一)Selenium库的工作原理
    Python:处理XML文件汇总
    蛋白质相互作用
    filebeat(8.9.0)采集日志到logstash,由logstash发送的es
  • 原文地址:https://blog.csdn.net/weixin_47109902/article/details/127744395