Spring Boot 基于Spring Initializer 的快速构建 day02

时间:2023-03-08 19:53:15

一、基于Spring Initializr 快速构建Spring Boot项目(快速)

   备注:需要联网

    这是使用Intellij Idea快速构建可以为我们省去大量的pom.xml配置时间,简单操作,可谓是程序员必会技巧。如果您是使用的开发工具是Eclipse那么你必须在Eclipse中下载Spring插件STS,然后创建Spring Starter Project即可。

   1.在idea开发工具右键new>>"Project">>"Spring Initializr"

    Spring Boot 基于Spring Initializer 的快速构建  day02

  2.接着,写项目的版本等等信息。

    Spring Boot 基于Spring Initializer 的快速构建  day02

   3.点击“finish”,日常点击开启自动导入功能

    Spring Boot 基于Spring Initializer 的快速构建  day02

  4.创建的项目的目录结构如下。可以删除没用的文件和文件夹。

Spring Boot 基于Spring Initializer 的快速构建  day02

  5.分析项目的工程目录结构

  Spring Boot 基于Spring Initializer 的快速构建  day02

    5.1 快速构建帮我们创建程序的主程序入口,不用是在手动配置了。

      Spring Boot 基于Spring Initializer 的快速构建  day02

    5.2 增加如下文件,其对应的作用

       --static--  用于存在静态资源如:css、js、image

       --templates--     保存页面模板(在SpringBoot的jar包中默认嵌入了tomcat默认不支持jsp页面)但是可以使用模板引擎如(freeMarker,thymeleaf)可以完全替代jsp

       --application.properites--  这是SpringBoot配置文件,主要的作用是用于配置SpringBoot默认的配置。如tomcat端口、还有数据的插入。其实SpringBoot还有另一种全局配置的写法命名是固定的“application.yml”

        --pom.xml--   在pom.xml中已经自动的帮我们导入对应功能的启动器。例如。

      

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

   5.3需求:在项目中还是输出hello World。还是成功的。

    Spring Boot 基于Spring Initializer 的快速构建  day02