快速搭建springboot項(xiàng)目(新手入門(mén))
一、創(chuàng)建項(xiàng)目
1.1、創(chuàng)建項(xiàng)目
1.2、配置編碼
1.3、取消無(wú)用提示
1.4、取消無(wú)用參數(shù)提示
二、添加POM父依賴
<!-- 兩種方式添加父依賴或者import方式 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.7</version> </parent>
maven的pom文件手動(dòng)更新
添加完成maven的pom文件之后,會(huì)自動(dòng)更新,也可能不會(huì)自動(dòng)更新,那么我們需要手動(dòng)更新它。
三、支持SpringMVC
<dependencies> <!-- 支持SpringMVC --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
四、創(chuàng)建啟動(dòng)類(lèi)、rest接口
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class StartApplication { public static void main(String[] args) { SpringApplication.run(StartApplication.class, args); } }
五、配置插件
配置完成后,maven打包可以生成可執(zhí)行jar文件
<build> <plugins> <!-- 打包成可執(zhí)行jar --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!-- 配置跳過(guò)測(cè)試 --> <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin> <!-- 配置jdk版本11 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>11</source> <target>11</target> <encoding>utf-8</encoding> </configuration> </plugin> </plugins> </build>
六、添加thymeleaf模板
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
七、添加配置
在resources文件夾下,創(chuàng)建application.properties
在resources文件夾下,創(chuàng)建templates文件夾
# 應(yīng)用名稱(chēng) spring.application.name=thymeleaf # 應(yīng)用服務(wù) WEB 訪問(wèn)端口 server.port=8080 # THYMELEAF (ThymeleafAutoConfiguration) # 開(kāi)啟模板緩存(默認(rèn)值: true ) spring.thymeleaf.cache=false # 檢查模板是否存在,然后再呈現(xiàn) spring.thymeleaf.check-template=true # 檢查模板位置是否正確(默認(rèn)值 :true ) spring.thymeleaf.check-template-location=true #Content-Type 的值(默認(rèn)值: text/html ) spring.thymeleaf.content-type=text/html # 開(kāi)啟 MVC Thymeleaf 視圖解析(默認(rèn)值: true ) spring.thymeleaf.enabled=true # 模板編碼 spring.thymeleaf.encoding=UTF-8 # 要被排除在解析之外的視圖名稱(chēng)列表,?逗號(hào)分隔 spring.thymeleaf.excluded-view-names= # 要運(yùn)?于模板之上的模板模式。另? StandardTemplate-ModeHandlers( 默認(rèn)值: HTML5) spring.thymeleaf.mode=HTML5 # 在構(gòu)建 URL 時(shí)添加到視圖名稱(chēng)前的前綴(默認(rèn)值: classpath:/templates/ ) spring.thymeleaf.prefix=classpath:/templates/ # 在構(gòu)建 URL 時(shí)添加到視圖名稱(chēng)后的后綴(默認(rèn)值: .html ) spring.thymeleaf.suffix=.html
八、添加controller
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class IndexController { @RequestMapping("/index") public ModelAndView index(){ ModelAndView mv = new ModelAndView(); mv.setViewName("index"); return mv; } } import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; @RestController public class HelloController { @GetMapping("/Hello") public String Hello(){ return "haha"; } } import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; /** * rest測(cè)試controller */ @RestController public class RestIndexController { @GetMapping("/restIndex") public String index(){ return "rest"; } }
九、添加html
在templates下創(chuàng)建index.html
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org" > <head> <meta charset="UTF-8"> <title>index</title> </head> <body> index </body> </html>
十、訪問(wèn)
需要maven執(zhí)行編譯,否則容易404
http://localhost:8080/index
到此這篇關(guān)于快速搭建springboot項(xiàng)目(新手入門(mén))的文章就介紹到這了,更多相關(guān)搭建springboot項(xiàng)目?jī)?nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 運(yùn)用springboot搭建并部署web項(xiàng)目的示例
- 使用IDEA搭建一個(gè)簡(jiǎn)單的SpringBoot項(xiàng)目超詳細(xì)過(guò)程
- IDEA上面搭建一個(gè)SpringBoot的web-mvc項(xiàng)目遇到的問(wèn)題
- Maven搭建springboot項(xiàng)目的方法步驟
- SpringBoot之Helloword 快速搭建一個(gè)web項(xiàng)目(圖文)
- 從零開(kāi)始搭建springboot+springcloud+mybatis本地項(xiàng)目全過(guò)程(圖解)
- SpringBoot+MyBatisPlus+Vue 前后端分離項(xiàng)目快速搭建過(guò)程(后端)
- IDEA基于支付寶小程序搭建springboot項(xiàng)目的詳細(xì)步驟
- idea快速搭建springboot項(xiàng)目的操作方法
- eclipse如何搭建Springboot項(xiàng)目詳解
- idea使用spring Initializr 快速搭建springboot項(xiàng)目遇到的坑
- 一文教會(huì)你如何搭建vue+springboot項(xiàng)目
相關(guān)文章
java如何寫(xiě)接口給別人調(diào)用的示例代碼
這篇文章主要介紹了java如何寫(xiě)接口給別人調(diào)用的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09淺談SpringBoot實(shí)現(xiàn)異步調(diào)用的幾種方式
本文主要介紹了淺談SpringBoot實(shí)現(xiàn)異步調(diào)用的幾種方式,主要包括CompletableFuture異步任務(wù),基于@Async異步任務(wù), TaskExecutor異步任務(wù),感興趣的可以了解一下2023-11-11MyBatis-Plus:saveOrUpdate根據(jù)指定字段更新或插入方式
這篇文章主要介紹了MyBatis-Plus:saveOrUpdate根據(jù)指定字段更新或插入方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-04-04Java的System.getProperty()方法獲取大全
這篇文章主要介紹了Java的System.getProperty()方法獲取大全,羅列了System.getProperty()方法獲取各類(lèi)信息的用法,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12IDEA啟動(dòng)Tomcat時(shí)控制臺(tái)出現(xiàn)亂碼問(wèn)題及解決
這篇文章主要介紹了IDEA啟動(dòng)Tomcat時(shí)控制臺(tái)出現(xiàn)亂碼問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02SpringBoot如何使用validator框架優(yōu)雅地校驗(yàn)參數(shù)
文章介紹了如何使用SpringValidation進(jìn)行參數(shù)校驗(yàn),包括引入依賴、@requestBody和@requestParam參數(shù)校驗(yàn)、統(tǒng)一異常處理、分組校驗(yàn)、嵌套校驗(yàn)、自定義校驗(yàn)、業(yè)務(wù)規(guī)則校驗(yàn)以及@Valid和@Validated的區(qū)別,同時(shí),列舉了常用的BeanValidation和HibernateValidator注解2025-02-02SpringBoot生成PDF的五種實(shí)現(xiàn)方法總結(jié)
這篇文章主要介紹了SpringBoot生成PDF的五種實(shí)現(xiàn)方法,在開(kāi)發(fā)中經(jīng)常會(huì)遇到需要進(jìn)行對(duì)一些數(shù)據(jù)進(jìn)行動(dòng)態(tài)導(dǎo)出PDF文件,然后讓用戶自己選擇是否需要打印出來(lái),這篇文章我們來(lái)介紹五種實(shí)現(xiàn)方法,需要的朋友可以參考下2024-10-10Java中隊(duì)列(Queue)和列表(List)的區(qū)別解析
Java中的列表(List)和隊(duì)列(Queue)是兩種常用的數(shù)據(jù)結(jié)構(gòu),它們分別用于不同的場(chǎng)景,列表是有序的,支持隨機(jī)訪問(wèn),允許重復(fù)元素,并且可以通過(guò)索引插入或刪除元素,下面通過(guò)本文給大家介紹Java中隊(duì)列(Queue)和列表(List)的區(qū)別,感興趣的朋友一起看看吧2025-03-03