方式一、 通过idea的Spring Initralizer
1、
new-->Project-->Spring Initralizer
填写项目信息:
Group:com.zb
Artifact:zbook
springboot version:2.0.4
2、
将
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
改成
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
3、
此时项目结构
image.png
maven clean一下,右键ZbookApplication运行,项目就跑起来了,就是这么简单,真正做到了开箱即用。
方式二、通过新建Maven配置依赖建立springboot项目
1、new-->Project-->Maven,填写项目信息
image.pngimage.png
maven项目的目录结构
image.png
2、添加依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
</parent>
<properties>
<spring-boot.version>2.2.2.RELEASE</spring-boot.version>
</properties>
<dependencies>
<!-- boot-web 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
</dependencies>
刷新maven,加载依赖
image.png
3、新建application.properties,并配置端口号
server.port=8007
新建启动文件,和控制器文件
image.png
配置启动文件
@SpringBootApplication
public class TestApp {
public static void main(String[] args) {
SpringApplication.run(TestApp.class, args);
System.out.println("启动成功");
}
}
这是项目就建好了。
网友评论