初識spring Boot 超精簡MVC實現

2021-07-29 15:29:20 字數 762 閱讀 6585

file-new -spring stater project  web依賴

@restcontroller

public string hello()

public static void main(string args)

}

localhost:8080/ 

10行實現springmvc 不需要配置任何xml檔案。

file-new-spring stater project  web thymeleaf依賴

@controller

public string hello()

public static void main(string args)

}

定向到index.html

index.html 放到resource/templates裡

hello springboot

localhost:8080/ 

上面2個程式主要的不同是 @restcontroller和@controller

@restcontroller 是@controller和responsebody的結合體 說明return的是response

ps:tomcat:

server.port=***

profile 不同環境對不同配置提供支援

spring.profiles.active= profile

初識springboot 引入thymeleaf

因為springboot不支援jsp 使用模板引擎 寫乙個頁面模板,和資料交給模板,生成乙個頁面。推薦thymeleaf 語法簡單功能強大,1.引入thymeleaf org.springframework.boot spring boot starter thymeleaf 修改版本 1.8 3....

Spring Boot 熱部署 超簡單

在目前的 spring boot 專案中,當發生了任何修改之後我們都需要重新啟動才能夠正確的得到效果,這樣會略顯麻煩,spring boot 提供了熱部署的方式,當發現任何類發生了改變,就會通過 jvm 類載入的方式,載入最新的類到虛擬機器中,這樣就不需要重新啟動也能看到修改後的效果了。我們往 po...

spring boot初識(三) 請求到頁面

服務接收到http請求後,跳轉到指定頁面。首先有乙個支援該請求的服務類,如下 controller public class htmlcontroller 在 springbootdemo src main resources templates目錄下放乙個簡單的靜態頁面 這是個靜態頁面。在瀏覽器中...