SpringBoot環(huán)境搭建圖文教程
什么是springboot?
Spring Boot俗稱微服務(wù)。Spring Boot是由Pivotal團(tuán)隊(duì)提供的全新框架,其設(shè)計(jì)目的是用來簡(jiǎn)化新Spring應(yīng)用的初始搭建以及開發(fā)過程。該框架使用了特定的方式來進(jìn)行配置,從而使開發(fā)人員不再需要定義樣板化的配置。通過這種方式,Spring Boot致力于在蓬勃發(fā)展的快速應(yīng)用開發(fā)領(lǐng)域(rapid application development)成為領(lǐng)導(dǎo)者。
1、新建一個(gè)maven工程
先選擇workspace
點(diǎn)擊【next】
直接默認(rèn),再點(diǎn)擊【next】
填寫groupid等~然后【finish】,到這里整個(gè)新建工程結(jié)束。
2、引入相關(guān)的jar包
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.8.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
這里說明下看似我們只引用了2個(gè)jar包其實(shí)里面包含了很多東西,像spring-boot-starter-web 我們通過壓縮包打開后
查看里面的pom文件可以看到如下所示的內(nèi)容,它引用了很多jar像spring的web,還有json的jar包都包含在內(nèi)了
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> </dependencies>
3、編寫程序入口類
package com.springbooot2; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * Hello world! * */ @SpringBootApplication public class App { public static void main(String[] args) throws Exception { SpringApplication.run(App.class, args); } }
這里說明下, @SpringBootApplication 就是為了讓spring掃描識(shí)別,告訴他我是一個(gè)程序入口類。
4、編寫請(qǐng)求響應(yīng)類
package com.springbooot2; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class FristBlood { @RequestMapping("/FristBlood") @ResponseBody public String hello() { return "dont worry,be happy!<br/><br/> <input type=\"submit\" value=\"ok\" />"; } }
這里說明下
@Controller 請(qǐng)求處理控制器類。
@RequestMapping 熟悉spring的都應(yīng)該不陌生,這是spring的東西,url映射。
@ResponseBody 響應(yīng)方法,我們的響應(yīng)信息都會(huì)被自動(dòng)轉(zhuǎn)化為json信息返回給前臺(tái)頁面
到這里整個(gè)代碼就擼完了,比起我們之前搭建一個(gè)ssh或者ssm之類的框架簡(jiǎn)單了不少,如果我們有那種只需要發(fā)送一個(gè)郵件啊。或者簡(jiǎn)單的服務(wù),用springboot可以說很方便了。
5、測(cè)試代碼
啟動(dòng)程序,打開瀏覽器,輸入:http://localhost:8080/FristBlood
請(qǐng)求頁面響應(yīng)結(jié)果如下圖。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
java中rss解析器(rome.jar和jdom.jar)示例
這篇文章主要介紹了java中rss解析器(rome.jar和jdom.jar)示例,需要的朋友可以參考下2014-03-03Java多線程編程中synchronized關(guān)鍵字的基礎(chǔ)用法講解
Java的synchronized關(guān)鍵字用于修飾線程同步,用以線程資源共享的目的等,下面就帶來簡(jiǎn)單的Java多線程編程中synchronized關(guān)鍵字的基礎(chǔ)用法講解2016-06-06springboot快速整合Mybatis組件的方法(推薦)
Spring Boot是由Pivotal團(tuán)隊(duì)提供的全新框架,其設(shè)計(jì)目的是用來簡(jiǎn)化新Spring應(yīng)用的初始搭建以及開發(fā)過程。這篇文章主要介紹了springboot快速整合Mybatis組件的方法,需要的朋友可以參考下2019-11-11mybatis參數(shù)類型不匹配錯(cuò)誤argument type mismatch的處理方案
這篇文章主要介紹了mybatis參數(shù)類型不匹配錯(cuò)誤argument type mismatch的處理方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-01-01使用SpringBoot簡(jiǎn)單實(shí)現(xiàn)無感知的刷新 Token功能
實(shí)現(xiàn)無感知的刷新 Token 是一種提升用戶體驗(yàn)的常用技術(shù),可以在用戶使用應(yīng)用時(shí)自動(dòng)更新 Token,無需用戶手動(dòng)干預(yù),這種技術(shù)在需要長時(shí)間保持用戶登錄狀態(tài)的應(yīng)用中非常有用,以下是使用Spring Boot實(shí)現(xiàn)無感知刷新Token的一個(gè)場(chǎng)景案例和相應(yīng)的示例代碼2024-09-09使用Servlet Filter實(shí)現(xiàn)系統(tǒng)登錄權(quán)限
這篇文章主要為大家詳細(xì)介紹了使用Servlet Filter實(shí)現(xiàn)系統(tǒng)登錄權(quán)限,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-10-10IDEA下使用Spring Boot熱加載的實(shí)現(xiàn)
本文主要介紹了IDEA下使用Spring Boot熱加載的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06