昨天以Vue作為我們前端框架的舉例,今天換以後端舉例囉!
Spring MVC

在維基百科中是這樣介紹Spring的:
Spring框架是 Java 平台的一個開源的全端(Full-stack)應用程式框架,一般被直接稱為 Spring。該框架的一些核心功能理論上可用於任何 Java 應用,Spring 還為基於Java企業版平台構建的 Web 應用提供了大量的擴充支援,並已經在 Java 社群中廣為流行。
那要如何建立Spring專案呢?
要建立Spring專案必須有以下步驟:
- 如果是用Eclipse作為開發環境的話,要選擇Java EE的版本(網址)
- 在Eclipse內需要有spring的相關套件,可以參考這篇(網址)
完成以上步驟後,我們來建立Spring專案吧
首先,選擇上方工具列的File->New->Other

再來,點選Spring的option,選擇Spring Legacy Project

接著,輸入Project name以及選擇SpringMVC

輸入完package name之後專案就建立完成了。
讓我們來看看Spring的目錄結構吧~

- Spring Element - 這邊存放了Spring的元件,如負責進行http request處理的RequestMapping。RequestMapping 是 Spring Web 應用程式中最常被用到的annotation之一。annotation 會將 HTTP 請求映射到 MVC 和 REST 控制器的處理方法上。
- src/main/java中的com.test.myapp中的HomeController負責了對應路由的邏輯。
- src/main/webapp/WEB-INF/views/home.jsp這個JSP檔則中的變數$(serverTime)就是HomeController中運算的變數之值。
- pom.xml - 這應該是這個專案中最重要的檔案沒有之一了,在Maven專案中,一定可以看到一個pom.xml的檔案,通常在出現在專案根目錄的位置。pom.xml的POM是Project Object Model(專案模型)的縮寫,是Maven專案的超級必要文件,其內容包含專案的描述,依賴,使用的plugin,及Maven該如何建置專案的等配置說明。他的功能就好像是node專案的package.json,負責紀錄專案中使用到的各個套件的相依性及版本號。簡單來說,Maven透過讀取pom.xml的設定來建置專案。
先這樣囉,明天見惹。
Hi, I am Grant.
個人部落格 - https://grantliblog.wordpress.com/
個人網站 - https://grantli-website.netlify.app/#/mainpage
我的寫作專題 - https://vocus.cc/user/5af2e9b5fd89780001822db4#