Spring Boot非常適合Web應用程序開發。使用spring-boot-starter-web模塊快速啓動和運行。 其中使用嵌入式Tomcat,Jetty或Undertow輕鬆創建自包含的HTTP服務器
Spring Boot支持多種方式來創建一個項目:
- 使用curl命令 Using curl
- 使用Spring Boot CLI 命令行工具 Using CLI
- https://spring.io/ 在線生成項目
- 使用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