使用springboot開發(fā)的第一個(gè)web入門程序的實(shí)現(xiàn)
1.新建一個(gè)springboot初始化項(xiàng)目

2.輸入自己的包名,項(xiàng)目名及jdk版本,再點(diǎn)擊Next

3.勾選Spring Web,再點(diǎn)擊Next

4.再點(diǎn)擊Next,再Finish 默認(rèn)的項(xiàng)目結(jié)構(gòu)如下圖

(1)修改pom.xml文件

完整的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)新建一個(gè)ControllerDemo類

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啟動(dòng)程序的目錄一定要在controller等目錄的至少上一級(jí),或者在SpringBootApplication 注解中添加屬性:
* @SpringBootApplication(scanBasePackages = {"com.zou.controller"})
*/
@RestController
public class ControllerDemo {
@RequestMapping("/demo")
public String demo(){
return "小鄒太帥了";
}
}
注:springBoot啟動(dòng)程序的目錄一定要在controller等目錄的至少上一級(jí),或者在SpringBootApplication 注解中添加屬性:

@SpringBootApplication(scanBasePackages = {"com.zou.controller"})
(3)在application.properties中修改端口號(hào)

server.port=8081
(4)測(cè)試

(5)打開瀏覽器,訪問(wèn)http://localhost:8081/demo,因?yàn)樵谥暗腃ontrollerDemo里面配置的訪問(wèn)路徑為/demo

(6)到這里第一個(gè)springboot開發(fā)web的入門程序就完成了。
到此這篇關(guān)于使用springboot開發(fā)的第一個(gè)web入門程序的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)springboot web入門 內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Mybatis-Plus中的@TableName 和 table-prefix使用
table-prefix 是一個(gè)全局配置,它會(huì)自動(dòng)在所有表名前添加指定的前綴,這個(gè)配置對(duì)于那些使用一致命名約定的數(shù)據(jù)庫(kù)表非常有用,這篇文章主要介紹了Mybatis-Plus中的@TableName 和 table-prefix使用,需要的朋友可以參考下2024-08-08
jsch中ChannelShell與ChannelExec的區(qū)別及說(shuō)明
這篇文章主要介紹了jsch中ChannelShell與ChannelExec的區(qū)別及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07
Java調(diào)用CXF WebService接口的兩種方式實(shí)例
今天小編就為大家分享一篇關(guān)于Java調(diào)用CXF WebService接口的兩種方式實(shí)例,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03
Java concurrency之非公平鎖_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
本篇文章主要介紹了Java concurrency之非公平鎖,詳細(xì)的介紹了獲取和釋放非公平鎖,有興趣的同學(xué)可以了解一下2017-06-06
Java 設(shè)計(jì)模式之責(zé)任鏈模式及異步責(zé)任鏈詳解
顧名思義,責(zé)任鏈模式(Chain of Responsibility Pattern)為請(qǐng)求創(chuàng)建了一個(gè)接收者對(duì)象的鏈。這種模式給予請(qǐng)求的類型,對(duì)請(qǐng)求的發(fā)送者和接收者進(jìn)行解耦。這種類型的設(shè)計(jì)模式屬于行為型模式2021-11-11
spring boot攔截器注入不了java bean的原因
這篇文章主要介紹了spring boot攔截器注入不了java bean的原因,幫助大家更好的理解和學(xué)習(xí)spring boot框架,感興趣的朋友可以了解下2020-11-11
手把手教你如何用JAVA連接MYSQL(mysql-connector-j-8.0.32.jar)
這篇文章主要介紹了關(guān)于如何用JAVA連接MYSQL(mysql-connector-j-8.0.32.jar)的相關(guān)資料,文中通過(guò)圖文介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用MySQL具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-01-01
Spring Data MongoDB中實(shí)現(xiàn)自定義級(jí)聯(lián)的方法詳解
這篇文章主要給大家介紹了關(guān)于Spring Data MongoDB中實(shí)現(xiàn)自定義級(jí)聯(lián)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-11-11
Spring Cloud Gateway使用Token驗(yàn)證詳解
這篇文章主要介紹了Spring Cloud Gateway使用Token驗(yàn)證詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-02-02

