简介:本文将指导读者如何使用IntelliJ IDEA集成开发环境搭建一个简易的Spring Boot项目。通过详细的步骤和图解,读者可以轻松地创建项目、配置依赖、编写代码并运行应用程序。
使用IntelliJ IDEA搭建简易Spring Boot项目
一、前提准备
二、创建Spring Boot项目
三、配置Spring Boot依赖
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.4</version></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies>
四、编写Spring Boot代码
HelloWorldController,用于处理Web请求。
package com.example.springbootdemo;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class HelloWorldController {@GetMapping("/")public String helloWorld() {return "Hello, World!";}}
SpringBootDemoApplication,用于启动Spring Boot应用程序。
package com.example.springbootdemo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class SpringBootDemoApplication {public static void main(String[] args) {SpringApplication.run(SpringBootDemoApplication.class, args);}}
五、运行Spring Boot应用程序
``bash
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _ | \ \ \ \
\/ )| |)| | | | | || (| | ) ) ) )
‘ |_| .|| ||_| |\, | / / / /
=========||==============|__/=///_/
:: Spring Boot :: (v2.5.4)
2023-04-01 10:00:00.000 INFO 12345 —- [ main] c.e.springbootdemo.SpringBootDemoApplication : Starting SpringBootDemoApplication using Java 1.8.0_281 on my-computer with PID 12345 (C:\path\to\project\target\classes started by username in C:\path\to\project)
…
2023-04-01 10:00:01.000 INFO 12345 —- [ main]