首頁  >  文章  >  Java  >  PlayFramework完整實作一個APP(六)

PlayFramework完整實作一個APP(六)

黄舟
黄舟原創
2016-12-23 16:41:421139瀏覽

需要為Blog新增檢視與發表評論的功能

 

1.建立檢視功能

application.java中新增show() 方法

public static void show(Long id) {
post public static void show(Long id) {
id);
   render(post);
}

 

建立 app/views/Application/show.html 


.
#{display post:post, as:'full' /}

  

在頁面模板中加入連結

訪問Blog

訪問Bloga Application.show(_post.id)}">${_post.title}

 

回頁

${blogTitle}

  

2.建立路由規則

當前頁URL http://localhost:9000/application/show?id=3

是由* /{controller}/{action} {controller}.{action} 這條規則解析得到的

在之前新建過Route

GET     /posts/{id}      訪問路徑變為 http:/ /localhost:9000/posts/3

  

更多路由語法參考: http://play-framework.herokuapp.com/zh/routes#syntax

 

3.新增頁導航,PRevious()next()

public Post previous() {

   return Post.find("postedAt }


, ext(return
} Post.find("postedAt > ? order by postedAt asc", postedAt).first();
}


  

show.html 

.previous()}

       
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn