springboot項(xiàng)目搭建一

# 一、工具

1. 使用簡(jiǎn)書(shū)記錄每天的學(xué)習(xí)進(jìn)度以及感想總結(jié)

2. 使用github進(jìn)行代碼的托管? 項(xiàng)目地址 https://github.com/gaofengfengfeng/HttpChat.git

3. 使用idea開(kāi)發(fā)

4. Atom開(kāi)發(fā)日志的記錄

# 二、每日工作安排

1-7 springboot項(xiàng)目的搭建以及啟動(dòng)

1. 新建一個(gè)HttpChat的maven項(xiàng)目




2. 導(dǎo)入與springboot相關(guān)的maven依賴(lài),導(dǎo)入maven依賴(lài)后,需要進(jìn)行reimport更新項(xiàng)目依賴(lài)。后續(xù)使用的依賴(lài)會(huì)用到什么添加什么。

```

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"

? ? ? ? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

? ? ? ? xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

? ? <modelVersion>4.0.0</modelVersion>

? ? <groupId>com.chat</groupId>

? ? <artifactId>httpchat</artifactId>

? ? <version>1.0-SNAPSHOT</version>

? ? <parent>

? ? ? ? <groupId>org.springframework.boot</groupId>

? ? ? ? <artifactId>spring-boot-starter-parent</artifactId>

? ? ? ? <version>1.5.6.RELEASE</version>

? ? </parent>

? ? <dependencies>

? ? ? ? <!-- web項(xiàng)目的啟動(dòng)依賴(lài) -->

? ? ? ? <dependency>

? ? ? ? ? ? <groupId>org.springframework.boot</groupId>

? ? ? ? ? ? <artifactId>spring-boot-starter-web</artifactId>

? ? ? ? </dependency>

? ? </dependencies>

</project>

```


3. 新建包結(jié)構(gòu),在這里新建的包名是com.chat.httpchat

4. 創(chuàng)建springboot項(xiàng)目啟動(dòng)類(lèi),Application.java。 注意:Application.java應(yīng)該在目錄的最外層,不然管理不到整個(gè)項(xiàng)目的文件,導(dǎo)致之后的注解無(wú)效。 并且,啟動(dòng)類(lèi)文件不能在默認(rèn)包下

5. springboot是通過(guò)簡(jiǎn)單的注解實(shí)現(xiàn)項(xiàng)目的啟動(dòng)的,最起碼需要在啟動(dòng)類(lèi)上添加@SpringBootApplication注解

6. 在Application類(lèi)中,添加main方法,以啟動(dòng)該springboot項(xiàng)目

7. 添加controller包,并實(shí)現(xiàn)helloworld的API接口。 新建一個(gè)HelloWorldController類(lèi)。添加@RestController注解,以實(shí)現(xiàn)接口類(lèi)的注冊(cè)

8. 新建一個(gè)接口,使其返回hello字符串。 注意添加@RequestMapping注解

9. 啟動(dòng)該項(xiàng)目,如果沒(méi)有配置啟動(dòng)的端口號(hào),則會(huì)默認(rèn)分配一個(gè)端口號(hào)


10. 如何請(qǐng)求到指定接口,并獲得其返回內(nèi)容? 請(qǐng)求地址= http://ip地址:端口號(hào)/uri? uri=每一級(jí)requestMapping value的拼接? 比如:http://127.0.0.1:8080/helloworld/hello? 本機(jī)地址=localhost=127.0.0.1

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容