【SpringBoot】使用IDEA创建SpringBoot项目
warning:
这篇文章距离上次修改已过426天,其中的内容可能已经有所变动。
在IntelliJ IDEA中创建Spring Boot项目的步骤如下:
- 打开IntelliJ IDEA。
- 点击
Create New Project。 - 选择
Spring Initializr,然后点击Next。 - 输入
Project Metadata信息,如Java Version、Group和Artifact,然后点击Next。 - 选择
Dependencies,可以选择需要的Spring Boot Starter依赖,比如Web来包含Spring Web模块。 - 输入项目
Name和Location,然后点击Finish。
IDEA会自动下载并导入Spring Boot项目所需的依赖,并创建一个简单的 "Hello World" 应用。
以下是一个简单的Spring Boot应用的代码示例:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorldController {
@GetMapping("/hello")
public String hello() {
return "Hello, World!";
}
}运行 main 方法,Spring Boot应用将启动,并且可以通过访问 http://localhost:8080/hello 获取 "Hello, World!" 响应。
评论已关闭