Intellij Idea簡化了春季啟動的開發,使其成為Java開發人員的最愛。 它的慣例與配置方法最小化了樣板代碼,從而使開發人員可以專注於業務邏輯。本教程演示了兩種用於在Intellij Idea中創建和運行基本春季啟動應用程序的方法。
>這種強大的IDE促進了具有必要依賴項的項目創建,並導入現有的Spring Boot項目。 在開始之前,請確保您有:
>步驟1:Intellij Ideas安裝
>訪問Intellij Idea網站:newProject
選擇所需的依賴項(例如,春季Web)。
>步驟3:創建和配置Spring Boot Project
方法1:使用Spring Initializr
在Intellij Idea中打開下載的zip文件。
controller
在newProject -> src/main/java
軟件包中創建一個類ExampleC
controller
>將以下代碼添加到
ExampleC
>package org.example.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class ExampleC { @RequestMapping("/firstApp") @ResponseBody public String firstSpringApp(){ return "Welcome!"; } }
pom.xml
>標籤中添加以下依賴項:<dependencies>
package org.example.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class ExampleC { @RequestMapping("/firstApp") @ResponseBody public String firstSpringApp(){ return "Welcome!"; } }
@SpringBootApplication
>添加
SpringApplication.run(Main.class, args);
main
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>2.5.3</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.5.3</version> </dependency> </dependencies>
ExampleC
步驟5:查看結果
>通過的瀏覽器訪問該應用程序。您應該看到“歡迎!”。
http://localhost:8080/firstApp
以上是如何在Intellij中運行第一個春季啟動應用程序?的詳細內容。更多資訊請關注PHP中文網其他相關文章!