當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
IDEA运行第一个Spring Boot应用程序
生活随笔
收集整理的這篇文章主要介紹了
IDEA运行第一个Spring Boot应用程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
根據《Spring Boot 實戰派》第三章使用開發工具進行練習
對應書籍31-33頁
1.構建Spring Boot 項目
借助安裝好的Spring Assistant創建。
1)單擊IDEA菜單欄File-New-Project ,在彈出的窗口中選擇 Spring Assistant
2)選擇default選項,單擊next按鈕
這里默認即可
3)找到spring boot版本和添加依賴。這里是developer tools下選擇Lombok;Web下選擇Spring Web,然后點擊next按鈕。
以上完成Spring Boot項目的創建,并添加了Web和Lombok依賴。
2.編寫控制器,實現輸出功能
控制器所在目錄如下圖所示,在HelloWord-src-main-java下,右擊com.example.demo,選擇new-java class
創建完結果如下
在HelloWorldController類輸入如下代碼
package com.example.demo; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class HelloWorldController {@RequestMapping("/hello")public String hello(){return "Hello,Spring Boot!";}}3.在IDEA運行
1)單擊demoApplication,點擊第7行的綠色箭頭,執行代碼
2)訪問網址
http://localhost:8080/hello這里8080是默認端口
4.運行結果
在網頁中可以看到如下內容
總結
以上是生活随笔為你收集整理的IDEA运行第一个Spring Boot应用程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IDEA报错Web server fai
- 下一篇: 中国国土面积960万平方公里,印度多少?