Intellij IDEA 一般可以通过两种方式创建 Spring Boot 项目:
1. 使用 IntelliJ IDEA 创建一个名称为 helloworld 的 Maven 项目
项目目录
<project>...<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.4.5</version><relativePath></relativePath> <!-- lookup parent from repository --></parent><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>...</project>
更新pom
2. 在com.study.start包下,创建一个名为 MyApplication 主程序,用来启动 Spring Boot 应用,代码如下。
package com.study.start;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}}

选择 Spring Boot 的版本及所依赖的 Spring Boot 组件

直接运行启动类 Helloworld2Application 中的 main() 方法,便可以启动该项目
\helloworld2\src\main\java\com\example\helloworld2\controller\HelloController.java
package com.example.helloworld2.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;@Controllerpublic class HelloController {@ResponseBody@RequestMapping("/hello")public String hello() {return "Hello World!";}}
访问接口地址:
http://localhost:8080/hello

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号