通過簡(jiǎn)單方法實(shí)現(xiàn)spring boot web項(xiàng)目
搭建效果為:
直接在網(wǎng)頁輸入請(qǐng)求,在頁面中顯示一行文字:Hello,Spring Boot
與一般的wen項(xiàng)目不同的地方:
1、不需要配置web.xml 文件,但需要注解@SpringBootApplication 等
2、一切和spring有關(guān)的jar包都不需要版本號(hào),springcloud會(huì)給你選擇它最穩(wěn)定的版本
3、它會(huì)定位public static void main()方法來標(biāo)記為可運(yùn)行類,必須在主路徑下
4、啟動(dòng)方式:
a.右鍵運(yùn)行main方法
b.由于我們使用了 spring-boot-starter-parent POM,所以可以使用 mvn spring-boot:run來啟動(dòng)項(xiàng)目(根路徑)
c.先使用Maven來package(打包),然后java -jar*-0.0.1-SNAPSHOT.jar。
搭建
創(chuàng)建一個(gè)新的maven項(xiàng)目,目錄結(jié)構(gòu)如下:

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.jiashubing</groupId>
<artifactId>spring-boot-web</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
HomeController.java文件
package cn.jiashubing.controller;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author jiashubing
* @since 2018/5/30
*/
@Controller
@EnableAutoConfiguration
public class HomeController {
@RequestMapping(value = "/home", method = RequestMethod.GET)
@ResponseBody
public String home() {
return "Hello,Spring Boot";
}
}
JiashubingApplication.java文件
package cn.jiashubing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author jiashubing
* @since 2018/5/29
*/
@SpringBootApplication
public class JiashubingApplication {
public static void main(String[] args) {
SpringApplication.run(JiashubingApplication.class, args);
}
}
在瀏覽器中輸入 http://localhost:8080/home
最終效果如下:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 使用Spring Boot搭建Java web項(xiàng)目及開發(fā)過程圖文詳解
- springboot web項(xiàng)目打jar或者war包并運(yùn)行的實(shí)現(xiàn)
- Spring Boot非Web項(xiàng)目運(yùn)行配置的方法教程
- Spring Boot非Web項(xiàng)目運(yùn)行的方法
- springboot登陸頁面圖片驗(yàn)證碼簡(jiǎn)單的web項(xiàng)目實(shí)現(xiàn)
- 運(yùn)用springboot搭建并部署web項(xiàng)目的示例
- 詳解Spring Boot Web項(xiàng)目之參數(shù)綁定
相關(guān)文章
Intellij IDEA實(shí)現(xiàn)springboot熱部署過程解析
這篇文章主要介紹了Intellij IDEA實(shí)現(xiàn)springboot熱部署過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08
springBoot 與neo4j的簡(jiǎn)單整合示例
這篇文章主要介紹了springBoot 與neo4j的簡(jiǎn)單整合示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-01-01
SpringCloud2020整合Nacos-Bootstrap配置不生效的解決
這篇文章主要介紹了SpringCloud2020整合Nacos-Bootstrap配置不生效的解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
Eclipse+Java+Swing實(shí)現(xiàn)圖書管理系統(tǒng)(詳細(xì)代碼)
這篇文章主要介紹了Eclipse+Java+Swing實(shí)現(xiàn)圖書管理系統(tǒng)并附上詳細(xì)代碼,需要的小伙伴可以參考一下,希望對(duì)你有所幫助2022-01-01
Spring boot動(dòng)態(tài)修改日志級(jí)別的方法
我們經(jīng)常會(huì)遇到業(yè)務(wù)想看debug日志的問題,但是debug日志頻繁打印會(huì)對(duì)日志查看有影響,且日志多對(duì)系統(tǒng)也會(huì)有一定的壓力,因此,如果可以在需要的時(shí)候動(dòng)態(tài)臨時(shí)調(diào)整下日志的級(jí)別則是比較完美的,spring boot已經(jīng)支持這種功能,需要的朋友可以參考下2022-12-12

