久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

使用springboot開發(fā)的第一個web入門程序的實現(xiàn)

瀏覽:90日期:2023-03-16 13:24:28

1.新建一個springboot初始化項目

使用springboot開發(fā)的第一個web入門程序的實現(xiàn)

2.輸入自己的包名,項目名及jdk版本,再點擊Next

使用springboot開發(fā)的第一個web入門程序的實現(xiàn)

3.勾選Spring Web,再點擊Next

使用springboot開發(fā)的第一個web入門程序的實現(xiàn)

4.再點擊Next,再Finish 默認的項目結(jié)構(gòu)如下圖

使用springboot開發(fā)的第一個web入門程序的實現(xiàn)

(1)修改pom.xml文件

使用springboot開發(fā)的第一個web入門程序的實現(xiàn)

完整的pom.xml為:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd'> <modelVersion>4.0.0</modelVersion> <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.4.5</version><relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.zou</groupId> <artifactId>springboot_demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springboot_demo</name> <description>Demo project for Spring Boot</description> <properties><java.version>1.8</java.version> </properties> <dependencies><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope></dependency><dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version></dependency><!--引入熱部署依賴--><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId></dependency><!--引入lombok組件--><dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.16</version></dependency><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional></dependency> </dependencies></project>

(2)新建一個ControllerDemo類

使用springboot開發(fā)的第一個web入門程序的實現(xiàn)

ControllerDemo的代碼如下

package com.zou.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/** * @author: 鄒祥發(fā) * @date: 2021/4/19 17:12 * springBoot啟動程序的目錄一定要在controller等目錄的至少上一級,或者在SpringBootApplication 注解中添加屬性: * @SpringBootApplication(scanBasePackages = {'com.zou.controller'}) */@RestControllerpublic class ControllerDemo { @RequestMapping('/demo') public String demo(){return '小鄒太帥了'; }}

注:springBoot啟動程序的目錄一定要在controller等目錄的至少上一級,或者在SpringBootApplication 注解中添加屬性:

使用springboot開發(fā)的第一個web入門程序的實現(xiàn)

@SpringBootApplication(scanBasePackages = {'com.zou.controller'})

(3)在application.properties中修改端口號

使用springboot開發(fā)的第一個web入門程序的實現(xiàn)

server.port=8081

(4)測試

使用springboot開發(fā)的第一個web入門程序的實現(xiàn)

(5)打開瀏覽器,訪問http://localhost:8081/demo,因為在之前的ControllerDemo里面配置的訪問路徑為/demo

使用springboot開發(fā)的第一個web入門程序的實現(xiàn)

(6)到這里第一個springboot開發(fā)web的入門程序就完成了。

到此這篇關(guān)于使用springboot開發(fā)的第一個web入門程序的實現(xiàn)的文章就介紹到這了,更多相關(guān)springboot web入門 內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 萨嘎县| 河曲县| 大新县| 阳泉市| 成安县| 云霄县| 石渠县| 礼泉县| 锡林郭勒盟| 灵石县| 台安县| 馆陶县| 噶尔县| 栖霞市| 恩施市| 兴业县| 永春县| 双牌县| 绥中县| 曲水县| 潮安县| 罗定市| 湟源县| 惠东县| 永仁县| 兴海县| 赤城县| 彰化县| 仲巴县| 杭锦后旗| 额敏县| 西藏| 平南县| 兴国县| 建瓯市| 红安县| 息烽县| 高雄市| 若尔盖县| 宽城| 临武县|