Spring Boot: 開發web 應用 - 01 創建項目

Spring Boot非常適合Web應用程序開發。使用spring-boot-starter-web模塊快速啓動和運行。 其中使用嵌入式Tomcat,Jetty或Undertow輕鬆創建自包含的HTTP服務器

Spring Boot支持多種方式來創建一個項目:

  1. 使用curl命令 Using curl
  2. 使用Spring Boot CLI 命令行工具 Using CLI
  3. https://spring.io/ 在線生成項目
  4. 使用Spring的集成開發工具

創建Spring Boot項目:

這裏簡單在線生成一個項目; 直接訪問https://start.spring.io/,填寫Group和Artifact,添加Web和 Freemarker兩個依賴項。
這裏寫圖片描述

Spring Boot 支持的可以替換JSP的,view engine包括: Thymeleaf, Groovy Markup Templates, Freemarker, Velocity. (As of Spring Framework 4.3, Velocity support has been deprecated due to six years without active maintenance of the Apache Velocity project. ) 除了Velocity 以外,其他根據個人愛好自助選擇。

添加HomeController

@Controller
public class HomePageController {

    @RequestMapping("/")
    public String home(){
        return "index";
    }
}

添加前端頁面的模板

採用開源bootstrap的H5 模板:awesome template
默認頁面文件需要添加至/src/main/resources/templates 下面;靜態資源文件的位置在/src/main/resources/static (或者/src/main/resources/public)下面。
目錄結構如下:
這裏寫圖片描述

運行SpringBootApplication主程序;訪問http://localhost:8080驗證。 截止目前,沒有任何定製的情況下,我們可以看到Awesome 的模板頁面。

github repo

spring-boot-trail-static-content tags/ootb

發佈了40 篇原創文章 · 獲贊 16 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章