play framework 使用教程

play framework 2.x 是使用scala與java開(kāi)發(fā)的一款框架、不能說(shuō)是一個(gè)框架應(yīng)該說(shuō)是一種解決方案。

play framework 優(yōu)點(diǎn)有如下幾個(gè):

  1. 開(kāi)發(fā)效率高、scala的特點(diǎn)函數(shù)式編程。
  2. 無(wú)狀態(tài)、可擴(kuò)展性極好。
  3. 熱部署、修改源碼直接動(dòng)態(tài)編譯、無(wú)需重啟服務(wù)。
  4. 優(yōu)秀的RESTFul框架。
  5. Play的生態(tài)圈在不斷擴(kuò)開(kāi)。

使用介紹

  1. jdk1.8環(huán)境安裝 (忽略)
  2. SBT安裝
  3. 模板框架使用

SBT安裝

使用版本為當(dāng)前文章時(shí)間點(diǎn)的最新版本1.2.8

Homebrew mac系統(tǒng)

brew install sbt@1

所有平臺(tái)壓縮包 sbt-1.2.8.zip

配置sbt的環(huán)境、與Java環(huán)境配置一樣

成功安裝如下

sbt -v
[process_args] java_version = '8'
# Executing command line:
java
-Xms1024m
-Xmx1024m
-XX:ReservedCodeCacheSize=128m
-XX:MaxMetaspaceSize=256m
-jar
/usr/local/Cellar/sbt/1.2.8/libexec/bin/sbt-launch.jar

[info] Loading global plugins from /Users/lake/.sbt/1.0/plugins
[info] Loading settings for project cc-build from plugins.sbt ...
[info] Loading project definition from /Users/lake/dounine/github/zhuxueyuan-play/cc/cc/project
[info] Loading settings for project root from build.sbt ...
[info] Set current project to cc (in build file:/Users/lake/dounine/github/zhuxueyuan-play/cc/cc/)
[info] sbt server started at local:///Users/lake/.sbt/1.0/server/dd2dc1e31d073ed11adb/sock
[cc] $

創(chuàng)建Java模板項(xiàng)目

sbt new playframework/play-java-seed.g8
[info] Loading global plugins from /Users/lake/.sbt/1.0/plugins
[info] Set current project to cc (in build file:/Users/lake/dounine/github/cc/)
[info] Set current project to cc (in build file:/Users/lake/dounine/github/cc/)

This template generates a Play Java project 

name [play-java-seed]: test
organization [com.example]: com.dounine    

Template applied in /Users/lake/dounine/github/cc/./test

運(yùn)行項(xiàng)目(首次運(yùn)行項(xiàng)目會(huì)下載包、這時(shí)間可以去喝一杯咖啡)

cd test
sbt run

成功結(jié)尾顯示如下

[info] Done updating.
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.

--- (Running the application, auto-reloading is enabled) ---

[info] p.c.s.AkkaHttpServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

(Server started, use Enter to stop and go back to the console...)

訪問(wèn)網(wǎng)頁(yè) http://localhost:9000

創(chuàng)建Scala模板項(xiàng)目(同上)

sbt new playframework/play-scala-seed.g8
cd test
sbt run

其它

訪問(wèn)不存在的接口則顯示如下

Intellij-idea debug調(diào)試如下

  1. debug方式運(yùn)行
sbt run -jvm-debug 9999
  1. 創(chuàng)建遠(yuǎn)程連接
  1. 直接對(duì)代碼debug即可

最后

后面會(huì)繼續(xù)出play framework實(shí)戰(zhàn)系列的文章、我在這等你。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容