
1.3 Spring Boot的简便创建方式
上面介绍的创建方式步骤有点多。在实际项目中,读者可结合具体的开发环境选择更简便的项目创建方式。下面介绍三种快捷创建方式。
1.3.1 在线创建
在线创建是Spring Boot官方提供的一种创建方式,在浏览器中输入网址“https://start.spring.io/”,可以看到如图1-11所示的页面。

图1-11
在这个页面中,可以选择项目的构建工具是Maven还是Gradle、语言是Java还是其他、要使用的Spring Boot版本号、项目的组织Id(包名)、模块名称以及项目的依赖。所有这些信息选好或填好后,单击Generate Project按钮将生成的模板下载到本地,解压后用IDE打开即可开始项目的开发。
1.3.2 使用IntelliJ IDEA创建
如果读者使用的开发工具是IntelliJ IDEA,那么可以直接创建一个Spring Boot项目,但是注意直接创建Spring Boot项目这个功能在社区版的IntelliJ IDEA上是不存在的。创建方式如下:
步骤01 创建项目时选择Spring Initializr,如图1-12所示。

图1-12
步骤02 输入项目基本信息,如图1-13所示。

图1-13
在这里输入项目的基本信息,包括组织Id、模块名称、项目构建类型、最终生成包的类型、Java的版本、开发语言、项目版本号、项目名称、项目描述以及项目的包。
步骤03 选择依赖,如图1-14所示。选择项目所需要添加的依赖,之后IntelliJ IDEA会自动把选中的依赖添加到项目的pom.xml文件中。

图1-14
步骤04 选择项目创建路径,如图1-15所示。

图1-15
经过上面4个步骤之后,一个可运行的Spring Boot项目就创建成功了。本书后面的项目都将采用这种方式来创建。
1.3.3 使用STS创建
也有开发者习惯使用STS创建。在STS中创建Spring Boot项目也很方便:首先右击,选择New→Spring Starter Project,如图1-16所示;然后在新页面中配置Spring Boot项目的基本信息(配置和IntelliJ IDEA的基本一致,不再赘述),如图1-17所示;最后选择需要添加的Starter,选择完成后,单击Finish按钮完成项目创建,如图1-18所示。

图1-16

图1-17

图1-18