第一個(gè)springboot程序Hello,World
我們將學(xué)習(xí)如何快速的創(chuàng)建一個(gè)Spring Boot應(yīng)用苗胀,并且實(shí)現(xiàn)一個(gè)簡(jiǎn)單的Http請(qǐng)求處理。通過(guò)這個(gè)例子對(duì)Spring Boot有一個(gè)初步的了解瓦堵,并體驗(yàn)其結(jié)構(gòu)簡(jiǎn)單、開發(fā)快速的特性歌亲。
我的環(huán)境準(zhǔn)備:
- java11
- Maven-3.6.3
- SpringBoot 2.x 最新版
開發(fā)工具:
- IDEA
一菇用、創(chuàng)建Springboot項(xiàng)目
建議把服務(wù)連接換成阿里云的:https://start.aliyun.com/
image
二、添加SpringWeb框架陷揪,再點(diǎn)擊完成
三惋鸥、可以選擇刪除多余文件
四杂穷、等待項(xiàng)目下載完成
image
五、springboot主啟動(dòng)類卦绣,springboot從這里開始跑
六耐量、新建controller包
image
白嫖資料
七、在controller包下新建HelloWorld類
package com.study.springboot01helloworld.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorld {
@RequestMapping("/hello")
public String HelloWorld01(){
return "HelloWorld";
}
}
八滤港、在Springboot主啟動(dòng)類啟動(dòng)項(xiàng)目
九廊蜒、項(xiàng)目啟動(dòng)完成
2溅漾、在網(wǎng)頁(yè)中輸入localhost:8080
3山叮、在網(wǎng)頁(yè)中輸入localhost:8080/hello
image