play框架02--細說目錄結構
play的目錄結構製作的相當精簡,以下是從play官網截下的圖片:
- app → Application sources
- └ assets → Compiled asset sources
-
└
- └ javascripts → Typically CoffeeScript sources
-
└
controllers
→
Application
controllers
- └ models → Application business layer
- └ views → Templates
-
build
.
sbt
→
Application
build script
- conf → Configurations files and other non - compiled resources ( on classpath )
- └ application . conf → Main configuration file
- └ routes → Routes definition
- dist → Arbitrary files to be included in your projects distribution
- public → Public assets
- └ stylesheets → CSS files
- └ javascripts → Javascript files
- └ images → Image files
- project → sbt configuration files
- └ build . properties → Marker for sbt project
- └ plugins . sbt → sbt plugins including the declaration for Play itself
- lib → Unmanaged libraries dependencies
- logs → Logs folder
- └ application . log → Default log file
- target → Generated stuff
- └ resolution - cache → Info about dependencies
- └ scala - 2.10
- └ api → Generated API docs
- └ classes → Compiled class files
- └ routes → Sources generated from routes
- └ twirl → Sources generated from templates
- └ universal → Application packaging
- └ web → Compiled web assets
- test → source folder for unit or functional tests
app目錄:
app目錄是程式碼目錄,包含了所有的Java或者Scala的原始碼,一般的“hello-world”sample程式都含有controllers、models、和views三個目錄,分別對應MVC三層結構中的:C、M和V;我想這大家都和清楚,大家還可以根據自己的專案需要建立其他的目錄,例如utils、dao等等。例如以下:
如果有需要,你還可以建一個名為“assets”的目錄,裡面可以放LESS或者CoffeeScript原始檔。
注意:這些controllers、models和views等目錄可以隨著你專案的需要而改變,例如:你可以寫成com.yourcompany.controllers、com.yourcompnay.model和com.yourcompany.views而不必非得寫成controllers、models和views。
conf目錄:
在這個目錄裡,放置的都是這個應用的一些配置檔案資訊,有兩個主要的檔案:
一個是application.conf:意思很明顯,就是整個應用的配置資訊,裡面會有一些配置的引數。包括資料庫連結中資料來源的資訊填寫,日誌列印的級別等資訊等等,還可以自定義一些引數。
注意:在conf中,play預設定義的有:資料庫資訊、應用資訊(名字、 Secret key、語言等)、日誌;這三塊兒的資訊,在conf中直接改後,效果會在應用程式中直接出現。
假如你想一用conf中自定義的配置引數:例如上圖中的阿里雲相關的資訊,你需要在application.conf中定義之後,在程式中使用
Play.configuration.getString("oss.access_id").getOrElse("diSnug5q4zb9y2mq")
來呼叫。實際上某人的那三塊資訊也是這麼來呼叫的。
假如你在application.conf中不想定義過多的自定義資訊,你也可以寫一個自定義的conf檔案,然後在application.conf中引用(include “fileName.conf”)如下:
routes:路由。非常重要的部分!使用方法非常簡單,在這裡定義你需要的rest介面,然後介面後面對應的處理函式。如下圖:
public 的目錄:
這裡放置的都是前端頁面相關的資訊,例如js、css、json檔案、圖片等等。
這些目錄檔案的名字是可以改的,但是引用的時候需要注意目錄名字。包括public的名字也是可以改的。前端頁面中需要其中的靜態檔案的話,需要再routes中新增:
然後在前端需要靜態檔案的地方這麼引用:
這裡就是用的public目錄下images目錄中的靜態檔案。
lib目錄:
如果之前你是做J2EE專案的,這個目錄你一定清楚,這就是放置其他依賴包的地方。(當然如果Maven有依賴連結,儘量用Maven的依賴連結)
build.sbt file:
這個檔案是整個專案新增依賴包的地方,所有的依賴都寫在這裡。如果你是J2EE開發者的話,你一定知道Maven的pom.xml檔案,在這裡,build.sbt檔案就相當於pom.xml的檔案。
project目錄:
這個目錄包含了sbt構建之後的東西:
1、pulgins.sbt:外掛sbt
2、build.properties:包含了sbt的版本。
target目錄:
target目錄包含了應用編譯之後的東西,就是編譯後的可執行檔案。
轉載https://blog.csdn.net/i6448038/article/details/48264503