• SpringBoot项目创建-基础篇


    Sping Boot 项目的本质其实还是一个 Maven 项目,项目创建通常有三种方式,Spring官方提供的在线Spring Initializr工具创建、IntelliJ IDEA 创建[通过开发工具创建]、以及Maven 创建。

    1.在线创建

    打开https://start.spring.io/ 生成 Spring Boot 项目。

    1. 填写相关信息
    • Project:表示使用什么构建工具,Maven or Gradle;
    • Language:表示使用什么编程语言, Java 、Kotlin or Groovy;
    • Spring Boot:Spring Boot 的版本;
    • Project Metadata:项目元数据,即 Maven项目基本元素,根据自己的实际情况填写;
    • Dependencies:要加入的 Spring Boot 组件;
    1. 然后点击生成或 Ctrl + Enter 即可生成项目
    2. 将压缩包下载后,解压缩后用 IDE 打开即可

    在这里插入图片描述

    2.IntelliJ IDEA 创建

    此实际原理同上

    1. 打开IDE新建项目时选择 Spring Initializr。

    在这里插入图片描述

    1. 选择spring boot版本并按需添加组件,然后Finish即可

    在这里插入图片描述

    3.Maven 创建

    通过引入springboot的依赖。

    1. 新建maven

    在这里插入图片描述

    1. 填写项目名和相关配置。

    在这里插入图片描述

    1. 点击Finish

    在这里插入图片描述

    1. pom.xml 添加依赖
    
    <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>org.examplegroupId>
        <artifactId>springboot-demoartifactId>
        <version>1.0-SNAPSHOTversion>
    
        <properties>
            <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
            <maven.compiler.source>1.8maven.compiler.source>
            <maven.compiler.target>1.8maven.compiler.target>
        properties>
    
        <parent>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-parentartifactId>
            <version>2.6.7version>
        parent>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-webartifactId>
            dependency>
        dependencies>
    
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.pluginsgroupId>
                        <artifactId>maven-compiler-pluginartifactId>
                        <version>2.5version>
                        <configuration>
                            <source>${maven.compiler.source}source>
                            <target>${maven.compiler.target}target>
                            <encoding>UTF-8encoding>
                        configuration>
                    plugin>
                plugins>
            pluginManagement>
        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
    1. 创建启动类。
    package cn.javaxxw.example;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    /**
     * 功能描述: 启动类
     * @author  Trazen
     * @date  2022/5/18 15:46
     */
    @SpringBootApplication
    @RestController
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class,args);
        }
    
        @GetMapping("/test")
        public String index() {
            return "Hello World!";
        }
    
    }
    
    
    • 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

    在这里插入图片描述

    1. 运行上一步骤中启动类的 main 方法即可;
      在这里插入图片描述
  • 相关阅读:
    嵌入式系统设计师之嵌入式程序设计语言
    Redis介绍
    .NET混合开发解决方案7 WinForm程序中通过NuGet管理器引用集成WebView2控件
    vs2010 webapi开发http请求以及website中如何实现http请求
    输入一个大写字母,程序根据输入字符在字母表的顺序位置n,输出一个高度为n的金字塔图形
    一文以概之:Java类成员加载顺序
    时序数据库选型
    深入URP之Shader篇1: URP Shader概述
    做自媒体如何在一个月内赚得三万?
    5_SqlSugar实体中的细节
  • 原文地址:https://blog.csdn.net/tuyong1972873004/article/details/126542903