自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Play 2.0的完整演示過(guò)程記錄

開(kāi)發(fā) 后端
介紹 Play 框架最好的方法就是給一個(gè)完整的演示步驟讓你看看 Play 到底有多簡(jiǎn)單。本演示使用最新的 Play 2.0 Beta 版。

介紹 Play 框架最好的方法就是給一個(gè)完整的演示步驟讓你看看 Play 到底有多簡(jiǎn)單。本演示使用最新的 Play 2.0 Beta 版。

本文是在 Linux 環(huán)境下進(jìn)行,如果你使用的 Windows,那會(huì)有一些小區(qū)別,例如路徑和環(huán)境變量的設(shè)置等等,請(qǐng)自行解決。

廢話(huà)少說(shuō),下面我們開(kāi)始:

1. 下載并安裝

  1. $ wget http://download.playframework.org/releases/play-2.0-beta.zip  
  2. $ unzip -q play-2.0-beta.zip  
  3. $ export PATH=$PATH:`pwd`/play-2.0-beta 

2. 創(chuàng)建一個(gè)新應(yīng)用

  1. $ play new tasks  
  2.    
  3. What is the application name?  
  4. > tasks  
  5.    
  6. Which template do you want to use for this new application?  
  7.    
  8.   1 - Create a simple Scala application  
  9.   2 - Create a simple Java application  
  10.   3 - Create an empty project  
  11.    
  12. 2 

來(lái)看看都生成了什么文件?

  1. $ find tasks -type f  
  2. tasks/.gitignore  
  3. tasks/app/controllers/Application.java  
  4. tasks/app/views/index.scala.html  
  5. tasks/app/views/main.scala.html  
  6. tasks/conf/application.conf  
  7. tasks/conf/routes  
  8. tasks/project/build.properties  
  9. tasks/project/Build.scala  
  10. tasks/project/plugins.sbt  
  11. tasks/public/images/favicon.png  
  12. tasks/public/javascripts/jquery-1.6.4.min.js  
  13. tasks/public/stylesheets/main.css 

3. 運(yùn)行程序

  1. $ cd tasks  
  2. $ play run 

然后你就可以打開(kāi)瀏覽器訪(fǎng)問(wèn) http://localhost:9000 , 你看到什么了嗎?

接下來(lái)我們加點(diǎn)動(dòng)態(tài)的數(shù)據(jù)

編輯 app/views/index.scala.html 文件,內(nèi)容如下:

  1. @(items: String)  
  2.    
  3. @main("Tasks") {  
  4.     <h1>@item</h1>  

編輯 app/controllers/Application.java 并修改 index() 方法,代碼如下(我們故意少輸入一個(gè)分號(hào))

  1. return ok(index.render("Things")) 

刷新一下 http://localhost:9000 頁(yè)面就會(huì)報(bào)一個(gè)模板編譯錯(cuò)誤:not found: value item.

該編譯錯(cuò)誤表明必須聲明模板參數(shù)

在控制臺(tái)中,輸入 Ctrl D 以停止 Play 程序,然后重新啟動(dòng) Play 控制并編譯程序:

  1. $ play  
  2. [tasks] $ compile 

在沒(méi)有運(yùn)行應(yīng)用的情況下你也可以發(fā)現(xiàn)這個(gè)模板編譯的錯(cuò)誤

再次啟動(dòng)應(yīng)用:

  1. [tasks] $ run 

在 app/views/index.scala.html 修復(fù)該錯(cuò)誤

刷新頁(yè)面,將顯示一個(gè) Java 的編譯錯(cuò)誤:';' expected

在 app/controllers/Application.java 中將那個(gè)缺少的分號(hào)加上。

再次刷新頁(yè)面,將顯示 Things 標(biāo)題

在 public/stylesheets/main.css 中,我們添加一些 css 代碼:

  1. body { font-family:"Helvetica Neue"padding:2embackground#B2EB5A url("/assets/images/play20header.png"no-repeat top center ; }  
  2. body:before { content:'Play 2.0 task list demo'color:rgba(255,255,255,0.7); font-size:150%text-transform:uppercaseletter-spacing:0.4em; }  
  3. ul { padding:0list-style:none; }  
  4. li, form { width:30embackground:whitepadding:1emborder:1px solid #ccc; border-radius:0.5emmargin:1em 0position:relativemin-height:1.2em; }  
  5. li a { text-decoration:nonecolor:transparentposition:absolute; top:1em; right:1em; }  
  6. li a:after { content:'❎'color:#aaafont-size:120%font-weight:bold; }  
  7. form * { font-size:120%; }  
  8. input { width:16em; }  
  9. button { cursor:pointercolorwhitebackground-color#3D6F04background-image: -webkit-linear-gradient(top#5AA706#3D6F04); text-shadow0 -1px 0 rgba(0000.25); border1px solid #CCCborder-color: rgba(0000.1) rgba(0000.1) rgba(0000.25); border-radius:4px; }  
  10. p.error { margin:0color:#c00; } 

在 app/controllers/Application.java 中,我們使用一個(gè)字符串 items 方法參數(shù)來(lái)替換 Things 字符串

在 conf/routes 中,我們替換第一條路由信息(使用小寫(xiě)的 string)

  1. GET /   controllers.Application.index(i: string) 

打開(kāi) http://localhost:9000/?items=Tasks 將顯示路由編譯錯(cuò)誤信息:

The routes file is compiled, and HTTP parameters must be declared. HTTP parameter names do not have to match the action method names.

在 conf/routes 中糾正這個(gè)錯(cuò)誤:

  1. GET /   controllers.Application.index(i: String) 

重新刷新頁(yè)面

撤銷(xiāo)剛剛在 app/controllers/Application.java 中的更改,刪除 index 方法參數(shù):

  1. public static Result index(final String items) {  
  2.    return ok(index.render(items));  

撤銷(xiāo)在 conf/routes 中的更改,刪除參數(shù):

  1. GET /   controllers.Application.index() 

下面還有在 IDEA 環(huán)境中的使用以及表單處理和驗(yàn)證等,詳情請(qǐng)看原文。

原文連接:http://www.oschina.net/question/12_33439

【編輯推薦】

  1. Play Framework 2.0 新特性介紹
  2. Play framework 2.0 Final發(fā)布
  3. Play Framework介紹:控制器層
  4. Play Framework框架安裝指南
  5. Play Framework框架概述
責(zé)任編輯:林師授 來(lái)源: 開(kāi)源中國(guó)社區(qū)
相關(guān)推薦

2012-03-14 09:29:00

Play framewJava

2012-03-14 12:29:55

JavaPlay Framwo

2010-03-30 08:45:35

Oracle導(dǎo)入

2009-11-17 17:17:50

PHP上傳多個(gè)文件

2011-03-02 18:23:55

安裝Proftpd

2012-02-29 10:54:21

JavaPlay Framew

2010-11-22 16:01:08

C++多態(tài)

2010-06-01 16:50:29

MySQL存儲(chǔ)過(guò)程

2012-02-20 14:47:08

JavaPlay

2011-09-09 17:01:42

框架

2023-09-02 21:50:21

2010-06-04 19:57:09

2012-07-30 10:26:59

2023-07-04 07:50:02

2012-02-22 15:51:22

JavaPlay Framew

2009-01-07 11:38:22

ASP.NET.NET錯(cuò)誤記錄

2009-08-06 16:18:38

C#調(diào)用SQL存儲(chǔ)過(guò)程

2010-05-26 17:57:44

MySQL 觸發(fā)器

2011-10-11 09:39:24

Web

2012-02-22 17:23:51

JavaPlay Framew
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)