PlayFramework记录--HomePage

 今天实现yabe的主页,形式如下:

    1、 程序启动时,给定个装载步骤,Bootstrap.java来实现,读取initial-data.yml中的内容;使得程序在没有任何http请求的情况下,执行数据的加载工作;Fixtures.loadModels("initial-data.yml"); 这个文件放置在conf目录下,修改数据库内容以后,要重新启动play
    

 

     2、controllers/Application.index()->render()->views/Application/index.html,显示html页面,这里要修改Application.java来获得frontPost及olderPosts
     frontPost=Post.find("order by postedAt desc").first();//日期降序排列的第一个即为最新的post;
     List<Post> olderPosts=Post.find("order by postedAt desc").from(1).fetch(10);//获得降序排列的第2个到第11个post,fetch(capacity)设置容量,from(beginIndex)设置起始的位置;
 
     3、修改index.html(模板里通过相同的名称来获取相同变量的内容)这句没有清楚latest by ${frontPost.comments[-1].author,这里-1是什么意思??
 
     4、index.html要有不同的展示方式(比如有不显示评论,或不显示内容等),使用一个tag来控制,类似于一个函数,可以从多个模板调用 。文件放在的/yabe/app/views/tags/display.htm,。#{display /}标签拥有两个参数:其中Post对象用于显示博文,第二参数用于确定主页的显示模式是home, teaser还是full
     full-全部内容
     home-只有post
     teaser-没有comments,也不含post内容
     
     5、重写index,从而避免代码重用。
     
     6、增加style,下载main.css来设置网页的样式,copy it to the /public/stylesheets/main.css file.
 
     7、保存工作,bzr st,add,commit...
posted on 2012-12-11 20:11  CodeAnt  阅读(203)  评论(0)    收藏  举报