最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

快速搭建springboot項(xiàng)目(新手入門(mén))

 更新時(shí)間:2023年07月12日 15:39:19   作者:弱水三千只取一瓢編號(hào)880908  
本文主要介紹了快速搭建springboot項(xiàng)目(新手入門(mén)),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

一、創(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)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java 使用 FFmpeg 處理視頻文件示例代碼詳解

    Java 使用 FFmpeg 處理視頻文件示例代碼詳解

    這篇文章主要介紹了Java 使用 FFmpeg 處理視頻文件示例代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • Jackson優(yōu)雅序列化Java枚舉類(lèi)過(guò)程解析

    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)題及解決

    這篇文章主要介紹了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)方法

    本篇文章主要介紹了java Quartz定時(shí)器任務(wù)與Spring task定時(shí)的幾種實(shí)現(xiàn)方法的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-02-02
  • SpringBoot中使用?POI的示例代碼

    SpringBoot中使用?POI的示例代碼

    這篇文章主要介紹了SpringBoot中使用POI的實(shí)例詳解,包括引入poi的jar包和創(chuàng)建excel的實(shí)例代碼,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-08-08
  • RocketMQ設(shè)計(jì)之同步刷盤(pán)

    RocketMQ設(shè)計(jì)之同步刷盤(pán)

    這篇文章主要介紹了RocketMQ設(shè)計(jì)之同步刷盤(pán),文章主要通過(guò)CommitLog的handleDiskFlush方法展開(kāi)全文內(nèi)容,實(shí)現(xiàn)同步刷盤(pán),下面文章詳細(xì)介紹,需要的小伙伴可以參考一下
    2022-03-03
  • Java進(jìn)程內(nèi)緩存框架EhCache詳解

    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)控利器詳解

    這篇文章主要介紹了Spring?boot?admin?服務(wù)監(jiān)控利器詳解,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-08-08
  • Spring MVC整合 freemarker及使用方法

    Spring MVC整合 freemarker及使用方法

    Spring MVC是一種基于Java的實(shí)現(xiàn)了Web MVC設(shè)計(jì)模式的請(qǐng)求驅(qū)動(dòng)類(lèi)型的輕量級(jí)Web框架,這篇文章主要介紹了Spring MVC整合 freemarker及使用方法,需要的朋友可以參考下
    2019-07-07
  • Spring?Security過(guò)濾器鏈加載執(zhí)行流程源碼解析

    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

最新評(píng)論

开封市| 台北县| 元朗区| 赤水市| 海盐县| 安宁市| 句容市| 望谟县| 洞头县| 鄂尔多斯市| 罗平县| 墨玉县| 宾川县| 夏河县| 富蕴县| 绥棱县| 同心县| 孟村| 漾濞| 泸西县| 盈江县| 威海市| 浑源县| 台中县| 延津县| 霍城县| 达州市| 长阳| 海阳市| 晋中市| 德钦县| 丹江口市| 泰兴市| 浪卡子县| 瑞安市| 鹤庆县| 许昌市| 花莲市| 西乌珠穆沁旗| 北票市| 政和县|