model中建的类,如Post(@Entity extends Model),在controller中建Posts类(extends CRUD)。
在application.conf中开启crud
module.crud=${play.path}/modules/crud
在routes中声明
#use the crud
* /admin module:crud
这样,在浏览器中输入localhost:9000/admin就可以看到model类的管理界面,可以进行添加,编辑,删除的功能。
在message.fr中,可以为model类中的各个字段起别名,如 postedAt=PostedAt(前为model字段名,后为显示名)。
标准化Post数据列表:
cd到项目里,输入命令
play crud:ov--template Posts/list,然后refresh就可以看到Posts里的list.html文件。
在list.html中,#{crud.table/}一行添加
#{crud.table fields:['content','post','author']/}
#{crud.table/}标签来生成表格,我们可以将我们想要的参数放进去(admin页面中显示的post数据的columns)。
当数据较多时,我们可以用#{crud.custom/}标签让它特定地显示字段的一部分内容。
我们也可以加一个delete按钮,在cmd:
play crud:ov--template Posts/show,然后refresh,就产生一个show.html文件,产生如下结果:
也可以通过修改#{crud.form/}标签来定义tags的样式。
定义tags的css样式,然后引用。