前言
使用Spring Initializer快速創建項目
步驟
首先肯定是打開我們的IDEA的編輯器呀~
創建項目
File -> New -> Project
Spring Initializr -> JDK版本 -> Next
Group -> Artifact -> Description
需要什么模塊選擇什么模塊,我這里只選擇Web功能
最后一步咯
等待模塊導入完成
創建Controller
右擊->New->Java Class
寫入Controller注解
package com.wangyang.springboot01helloworldquick.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
//@ResponseBody //這個類的所有方法返回的數據直接寫給瀏覽器(如果是對象轉為json數據)
//@Controller
/**
* @RestController == @ResponseBody + @Controller
*/
@RestController
public class HelloWorld {
@RequestMapping("/hello")
public String hello() {
return "Hello World";
}
}
運行主程序
訪問
總結
-
主程序會自動生成,只需要寫邏輯文件
-
resource文件中的目錄結構
static: 保存所有的靜態資源文件如:js,css,image;
templates: 保存所有的模板頁面(SpringBoot默認jar包嵌入式的Tomcat,默認不支持JSP頁面)
可使用模板引擎(freemarker,thymeleaf);
application.properties: SpringBoot應用的配置文件,可修改一些默認設置; -
自動創建的目錄結構