• SpringBoot SpringBoot 基础篇(第一篇) 第1章 SpringBoot 入门 1.3 SpringBoot 快速入门


    SpringBoot

    【千锋教育java教程SpringBoot2全套,springboot快速入门到项目实战视频教程】

    SpringBoot 基础篇(第一篇)

    第1章 SpringBoot 入门

    1.3 SpringBoot 快速入门

    官方指引:https://spring.io/quickstart

    在这里插入图片描述

    1.3.1 Maven 方式构建

    【目标】搭建SpringBoot工程,浏览器发送hello请求,服务器接受请求并处理,响应Hello World字符串。

    ① 创建一个普通的Maven 工程

    在这里插入图片描述

    创建

    在这里插入图片描述

    一个全新的Maven 工程。

    ② 导入SpringBoot 的依赖

    
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0modelVersion>
    
        <groupId>com.dingjiaxionggroupId>
        <artifactId>testartifactId>
        <version>1.0-SNAPSHOTversion>
    
        <parent>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-parentartifactId>
            <version>2.7.1version>
        parent>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-webartifactId>
            dependency>
        dependencies>
    
    project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    记得刷一下。

    在这里插入图片描述

    ③ 编写一个主程序,启动SpringBoot 应用

    package com.dingjiaxiong;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    /**
     * ClassName: HelloWorldMainApplication
     * date: 2022/10/14 15:01
     *
     * @author DingJiaxiong
     */
    
    /*
    * @SpringBootApplication 来标注⼀个主程序类
    * */
    
    @SpringBootApplication
    public class HelloWorldMainApplication {
        public static void main(String[] args) {
            SpringApplication.run(HelloWorldMainApplication.class,args);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    运行

    在这里插入图片描述

    ④ 编写相关的Controller

    package com.dingjiaxiong.controller;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    /**
     * ClassName: HelloController
     * date: 2022/10/14 15:03
     *
     * @author DingJiaxiong
     */
    
    @RestController
    public class HelloController {
        
        @RequestMapping("/hello")
        public String hello(){
            return "Hello world!!!";
        }
        
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    ⑤ 重启服务器,访问测试

    在这里插入图片描述

    1.3.2 用Spring Initializr 方式构建

    Spring Initializr是一个Web应用,它提供了一个基本的项目结构,能够帮助我们快速构建一个基础的Spring Boot项目

    在这里插入图片描述

    下一步

    在这里插入图片描述

    在这里插入图片描述

    一个全新的SpringBoot 工程

    在这里插入图片描述

    编写相关的Controller

    package com.dingjiaxiong.springboot_demo.controller;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    /**
     * ClassName: HelloController
     * date: 2022/10/14 15:10
     *
     * @author DingJiaxiong
     */
    
    @RestController
    public class HelloController {
        
        @RequestMapping("/hello")
        public String hello(String name){
            return "Hello world!!!!";
        }
        
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    启动程序,访问测试

    http://localhost:8080/hello

    在这里插入图片描述

    1.3.3 阿里云构建方式

    Spring Initializr是一个Web应用,关于Server URL的配置使用阿里云的地址就行

    https://start.aliyun.com
    
    • 1

    在这里插入图片描述

    不必不必。

  • 相关阅读:
    Day15用栈实现队列&用队列实现栈
    Ionic list - ion-item的相关用法
    CSP-J-2016-海港
    深入理解Java ThreadLocal及其内存泄漏防范
    【笔试题】【day17】
    Web前端:全栈开发人员——专业知识和技能
    【优化模型】求解二次规划问题
    计算机基础学习(好文必看)
    油猴脚本插件教程
    【成都信息工程大学】只考程序设计!成都信息工程大学计算机考研考情分析!
  • 原文地址:https://blog.csdn.net/weixin_44226181/article/details/127696456