需要为Blog添加 查看和发表评论的功能 1.创建查看功能 Application.java中添加 show() 方法 public static void show(Long id) { Post post = Post.findById(id); render(post); } 创建 app/views/Application/show.html #{extends 'main.html' /} #{set title:post.title /} #{display post:post, a…
添加权限控制 1.导入Secure module,该模块提供了一个controllers.Secure控制器. /conf/application.conf # Import the secure module module.secure=${play.path}/modules/secure /conf/routes # Import Secure routes * / module:secure 2.在Post Comment User Tag控制器上添加标签 @With(Secure.cl…
程序以及基本可用了,需要继续完善页面 1.创建页面模板 创建文件 app/views/tags/display.html *{ Display a post in one of these modes: 'full', 'home' or 'teaser' }* <div class="post ${_as == 'teaser' ? 'teaser' : ''}"> <h2 class="post-title"> <a href=&q…
1.开发DataModel 在app\moders 下新建User.java package models; import java.util.*; import javax.persistence.*; import play.db.jpa.*; @Entity public class User extends Model { public String email; public String password; public String fullname; public String…
添加测试 ApplicationTest.java @Test public void testAdminSecurity() { Response response = GET("/admin"); assertStatus(302, response); assertHeaderEquals("Location", "http://localhost/login", response); } 更多测试介绍 http://play-framew…
添加用户编辑区 1.修改Admin.index() public static void index() { List<Post> posts = Post.find("author.email", Security.connected()).fetch(); render(posts); } 2.修改页面 app/views/Admin/index.html #{extends 'admin.html' /} <h3>Welcome ${user}, <…
1.定制CRUD管理页面 > play crud:ov --layout 替换生成文件内容 app/views/CRUD/layout.html #{extends 'admin.html' /} #{set 'moreStyles'} <link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/crud.css'}&q…
1.定制Comment列表 新增加Comment list页面,执行命令行 > play crud:ov --template Comments/list 会生成/app/views/Comments/list.html  生成的文件中 #{crud.table /} 是表格的内容,可以替换为一下内容,显示更多的列 #{crud.table fields:['content', 'post', 'author'] /} 如果要对某一列的内容进行处理 #{crud.table fields:['c…
添加增删改查操作 1.开启CRUD Module 在/conf/application.conf 中添加 # Import the crud module module.crud=${play.path}/modules/crud 在/conf/routes 中添加 # Import CRUD routes * /admin module:crud 需要重启Server,导入CRUD Module 2.添加控制器 /app/controllers import play.*; import pl…
创建Tag标签 1.创建Model @Entity @Table(name = "blog_tag") public class Tag extends Model implements Comparable<Tag> { public String name; private Tag(String name) { this.name = name; } public String toString() { return name; } public int compare…