加入增刪改查作業
1.開啟CRUD Module
在/conf/application.conf 中加入
# Import the crud module
module.crud=$alplay.crud;
在/conf/routes 中加入
# Import CRUD routes
* /admin @ Module
public class Posts extends CRUD {
}public class Tags extends CRUD {}public class Users extends CRUD ext . }
可能會提示錯誤: CRUD 無法解析為類型 且執行程式會提示錯誤
解決方法:
修改 conf/dependencies.yml
運行Shell
> play dependencies
工程下會產生modules/crud 文件,重新啟動工程即可,但是編譯還是會出錯,可能是沒有引用crudControl
3
3.package controllers;import models.User;
@CRUD.For(User.class)public class AdminUsers extends CRUD {
}
class User extends Model {
@Email
@Required public String email;
@Require min; public String toString() { return email;
}
進入http://localhost:9000/admin/ 選擇add user進入User Form Date postedAt;
@ Lob
@Required
@MaxSize(10000) public String content;
@Require ", cascade = CascadeType.ALL) public List
@ManyToMany(cascade = CascadeType.PERSIST) public Set
}
public String name;
}
public class Comment extends Model {
@Required public String author;
@Required public Date po @MaxSize(10000) public String content;
@ManyToOne
@Required public Post post;
}
5.頁面上顯示的Label名字是小寫,與對應類別的字段名稱一致,如果想顯示大寫,可以修改/conf/messages
title=Title
content=Content
title=Title
content=ContentpostedAt
author=Author
post=Related post
tags=Tags set
name=Common name
password=Password
fullname=Full nameisAdmin=User password=Password
fullname=Full name
isAdmin== APP(九)的內容,更多相關內容請關注PHP中文網(www.php.cn)!