• SpringBoot3基础:最简项目示例


    说明

    本文建立一个最基本的SpringBoot3项目,依赖项仅包含 spring-web(SpringMVC)

    备注:SpringBoot3需要JDK17支持,配置方法参考:
    SpringBoot3项目中配置JDK17

    项目结构图示

    在这里插入图片描述

    POM

    
    <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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0modelVersion>
        <parent>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-parentartifactId>
            <version>3.1.3version>
            <relativePath/> 
        parent>
        <groupId>com.examplegroupId>
        <artifactId>hello-spring-boot3artifactId>
        <version>1.0version>
        <name>HelloSpringBoot3name>
        <description>Demo project for Spring Boot3description>
        <properties>
            <java.version>17java.version>
        properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-webartifactId>
            dependency>
    
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-testartifactId>
                <scope>testscope>
            dependency>
        dependencies>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.yamlgroupId>
                    <artifactId>snakeyamlartifactId>
                    <version>2.0version>
                dependency>
            dependencies>
        dependencyManagement>
    
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.bootgroupId>
                    <artifactId>spring-boot-maven-pluginartifactId>
                plugin>
            plugins>
        build>
    
    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
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53

    启动器:Application

    package com.example;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class HelloSpringBoot3Application {
    
        public static void main(String[] args) {
            SpringApplication.run(HelloSpringBoot3Application.class, args);
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    配置文件:yml

    使用的默认配置,未添加任何内容。

    控制器:Controller

    package com.example.web.controller;
    
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping("test")
    public class TestController {
    
        @GetMapping("hello")
        public String hello() {
            return "Hello SpringBoot3";
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    接口调用示例

    在这里插入图片描述

  • 相关阅读:
    比传统BPM更惊艳:基于低代码的流程管理系统
    springMvc45-自定义配置类
    实用,eBay账号关联问题该如何解决?
    车间作业分析重点分析的内容是哪些?
    尚硅谷大数据项目《在线教育之实时数仓》笔记005
    图片上传~
    【leetcode】最长斐波那契数列
    docker制作springboot镜像
    java:JDBC ResultSet结合Spring的TransactionTemplate事务模板的查询方式
    Spring 框架中都用到了哪些设计模式:单例模式、策略模式、代理模式
  • 原文地址:https://blog.csdn.net/sgx1825192/article/details/133064300