快速搭建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父依賴(lài)
<!-- 兩種方式添加父依賴(lài)或者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)文章
Jackson優(yōu)雅序列化Java枚舉類(lèi)過(guò)程解析
這篇文章主要介紹了Jackson優(yōu)雅序列化Java枚舉類(lèi)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-09-09
Mybatis中一條SQL使用兩個(gè)foreach的問(wèn)題及解決
這篇文章主要介紹了Mybatis中一條SQL使用兩個(gè)foreach的問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02
java Quartz定時(shí)器任務(wù)與Spring task定時(shí)的幾種實(shí)現(xiàn)方法
本篇文章主要介紹了java Quartz定時(shí)器任務(wù)與Spring task定時(shí)的幾種實(shí)現(xiàn)方法的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-02-02
Java進(jìn)程內(nèi)緩存框架EhCache詳解
這篇文章主要介紹了Java進(jìn)程內(nèi)緩存框架EhCache,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2021-12-12
Spring?boot?admin?服務(wù)監(jiān)控利器詳解
這篇文章主要介紹了Spring?boot?admin?服務(wù)監(jiān)控利器詳解,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08
Spring?Security過(guò)濾器鏈加載執(zhí)行流程源碼解析
Spring?Boot?對(duì)于?Spring?Security?提供了自動(dòng)化配置方案,可以使用更少的配置來(lái)使用?Spring?Security。那么這個(gè)過(guò)濾器鏈?zhǔn)窃趺醇虞d和實(shí)現(xiàn)攔截的呢,對(duì)Spring?Security過(guò)濾器鏈加載執(zhí)行流程感興趣的朋友一起看看吧2021-12-12

