欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

快速搭建springboot項目(新手入門)

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

一、創(chuàng)建項目

1.1、創(chuàng)建項目

1.2、配置編碼

1.3、取消無用提示

1.4、取消無用參數(shù)提示

二、添加POM父依賴

<!-- 兩種方式添加父依賴或者import方式 -->
<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.5.7</version>
</parent>

maven的pom文件手動更新

添加完成maven的pom文件之后,會自動更新,也可能不會自動更新,那么我們需要手動更新它。

三、支持SpringMVC

<dependencies>
    <!-- 支持SpringMVC -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

四、創(chuàng)建啟動類、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>
      <!-- 配置跳過測試 -->
      <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文件夾

# 應用名稱
spring.application.name=thymeleaf
# 應用服務(wù) WEB 訪問端口
server.port=8080
# THYMELEAF (ThymeleafAutoConfiguration)
# 開啟模板緩存(默認值: true )
spring.thymeleaf.cache=false
# 檢查模板是否存在,然后再呈現(xiàn)
spring.thymeleaf.check-template=true
# 檢查模板位置是否正確(默認值 :true )
spring.thymeleaf.check-template-location=true
#Content-Type 的值(默認值: text/html )
spring.thymeleaf.content-type=text/html
# 開啟 MVC Thymeleaf 視圖解析(默認值: true )
spring.thymeleaf.enabled=true
# 模板編碼
spring.thymeleaf.encoding=UTF-8
# 要被排除在解析之外的視圖名稱列表,?逗號分隔
spring.thymeleaf.excluded-view-names=
# 要運?于模板之上的模板模式。另? StandardTemplate-ModeHandlers( 默認值: HTML5)
spring.thymeleaf.mode=HTML5
# 在構(gòu)建 URL 時添加到視圖名稱前的前綴(默認值: classpath:/templates/ )
spring.thymeleaf.prefix=classpath:/templates/
# 在構(gòu)建 URL 時添加到視圖名稱后的后綴(默認值: .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測試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>

十、訪問

需要maven執(zhí)行編譯,否則容易404

http://localhost:8080/index

到此這篇關(guān)于快速搭建springboot項目(新手入門)的文章就介紹到這了,更多相關(guān)搭建springboot項目內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java如何寫接口給別人調(diào)用的示例代碼

    java如何寫接口給別人調(diào)用的示例代碼

    這篇文章主要介紹了java如何寫接口給別人調(diào)用的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-09-09
  • 淺談SpringBoot實現(xiàn)異步調(diào)用的幾種方式

    淺談SpringBoot實現(xiàn)異步調(diào)用的幾種方式

    本文主要介紹了淺談SpringBoot實現(xiàn)異步調(diào)用的幾種方式,主要包括CompletableFuture異步任務(wù),基于@Async異步任務(wù), TaskExecutor異步任務(wù),感興趣的可以了解一下
    2023-11-11
  • java IO流文件的讀寫具體實例

    java IO流文件的讀寫具體實例

    這篇文章主要介紹了java IO流文件的讀寫具體實例,有需要的朋友可以參考一下
    2013-12-12
  • MyBatis-Plus:saveOrUpdate根據(jù)指定字段更新或插入方式

    MyBatis-Plus:saveOrUpdate根據(jù)指定字段更新或插入方式

    這篇文章主要介紹了MyBatis-Plus:saveOrUpdate根據(jù)指定字段更新或插入方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2025-04-04
  • Java的System.getProperty()方法獲取大全

    Java的System.getProperty()方法獲取大全

    這篇文章主要介紹了Java的System.getProperty()方法獲取大全,羅列了System.getProperty()方法獲取各類信息的用法,具有一定的參考借鑒價值,需要的朋友可以參考下
    2014-12-12
  • Java中自定義注解類及使用實例解析

    Java中自定義注解類及使用實例解析

    這篇文章主要介紹了Java中自定義注解類并使用過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-11-11
  • IDEA啟動Tomcat時控制臺出現(xiàn)亂碼問題及解決

    IDEA啟動Tomcat時控制臺出現(xiàn)亂碼問題及解決

    這篇文章主要介紹了IDEA啟動Tomcat時控制臺出現(xiàn)亂碼問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • SpringBoot如何使用validator框架優(yōu)雅地校驗參數(shù)

    SpringBoot如何使用validator框架優(yōu)雅地校驗參數(shù)

    文章介紹了如何使用SpringValidation進行參數(shù)校驗,包括引入依賴、@requestBody和@requestParam參數(shù)校驗、統(tǒng)一異常處理、分組校驗、嵌套校驗、自定義校驗、業(yè)務(wù)規(guī)則校驗以及@Valid和@Validated的區(qū)別,同時,列舉了常用的BeanValidation和HibernateValidator注解
    2025-02-02
  • SpringBoot生成PDF的五種實現(xiàn)方法總結(jié)

    SpringBoot生成PDF的五種實現(xiàn)方法總結(jié)

    這篇文章主要介紹了SpringBoot生成PDF的五種實現(xiàn)方法,在開發(fā)中經(jīng)常會遇到需要進行對一些數(shù)據(jù)進行動態(tài)導出PDF文件,然后讓用戶自己選擇是否需要打印出來,這篇文章我們來介紹五種實現(xiàn)方法,需要的朋友可以參考下
    2024-10-10
  • Java中隊列(Queue)和列表(List)的區(qū)別解析

    Java中隊列(Queue)和列表(List)的區(qū)別解析

    Java中的列表(List)和隊列(Queue)是兩種常用的數(shù)據(jù)結(jié)構(gòu),它們分別用于不同的場景,列表是有序的,支持隨機訪問,允許重復元素,并且可以通過索引插入或刪除元素,下面通過本文給大家介紹Java中隊列(Queue)和列表(List)的區(qū)別,感興趣的朋友一起看看吧
    2025-03-03

最新評論