国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

使用springboot開發的第一個web入門程序的實現

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

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

使用springboot開發的第一個web入門程序的實現

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

使用springboot開發的第一個web入門程序的實現

3.勾選Spring Web,再點擊Next

使用springboot開發的第一個web入門程序的實現

4.再點擊Next,再Finish 默認的項目結構如下圖

使用springboot開發的第一個web入門程序的實現

(1)修改pom.xml文件

使用springboot開發的第一個web入門程序的實現

完整的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開發的第一個web入門程序的實現

ControllerDemo的代碼如下

package com.zou.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/** * @author: 鄒祥發 * @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開發的第一個web入門程序的實現

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

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

使用springboot開發的第一個web入門程序的實現

server.port=8081

(4)測試

使用springboot開發的第一個web入門程序的實現

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

使用springboot開發的第一個web入門程序的實現

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

到此這篇關于使用springboot開發的第一個web入門程序的實現的文章就介紹到這了,更多相關springboot web入門 內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 迁西县| 荆州市| 文安县| 济源市| 嵊州市| 拉孜县| 新巴尔虎左旗| 禄劝| 岳阳县| 田阳县| 甘洛县| 印江| 巴彦淖尔市| 嘉鱼县| 海安县| 定日县| 车险| 柳江县| 米林县| 甘孜| 六安市| 建阳市| 镇坪县| 西乌珠穆沁旗| 巴楚县| 镇沅| 东乌珠穆沁旗| 阿拉善盟| 新田县| 梁山县| 绥中县| 乌审旗| 洛浦县| 新蔡县| 建平县| 炎陵县| 扎鲁特旗| 荆州市| 明光市| 大新县| 兰考县|