Add additions and deletions to change the operation
1. Turn on the crud Module
Add in /conf/application.conf
# Import the crud Modulemodule.crud=${play.path}/modules/crud
Add in /conf/routes
# Import CRUD routes* /admin Module:crud
Need to restart server to import crud Module
2. Adding a Controller
/app/controllers
import play.*; import play.mvc.*publicclassextends CRUD { }public classextends CRUD { }publicclassextends crud { }publicclassextends crud { }
Error may be prompted: CRUD cannot resolve to type and running program will prompt for errors
Workaround:
Modify conf/dependencies.yml
Require: -play -play---crud
Run the shell
> Play Dependencies
The project will generate a Modules/crud file, restart the project, but the compilation will be error, it may not be the reason to reference the CRUD project
3. Create a Controller
Package controllers; Import models. User; @CRUD. For (User. class )publicclassextends CRUD {}
4. Modify model, add validation
Take user as an example
Public class extends Model { @Email @Required public String Email; @Required @Password public String Password; Public String fullname; Public String isadmin; Public String toString () { return email; }}
Enter http://localhost:9000/admin/Select Add user to enter user form for testing
Public classPostextendsModel {@Required PublicString title; @Required PublicDate Postedat; @Lob @Required @MaxSize (10000) PublicString content; @Required @ManyToOne PublicUser author; @OneToMany (Mappedby= "POST", Cascade =Cascadetype.all) PublicList<comment>comments; @ManyToMany (Cascade=cascadetype.persist) PublicSet<tag>tags;}
Public class extends Implements Comparable<tag> { @Required public String name;}
Public class extends Model { @Required public String author; @Required public Date postedat; @Lob @Required @MaxSize (10000) public String content; @ManyToOne @Required public post post;}
5. The label name displayed on the page is lowercase, consistent with the field name of the corresponding class, and if you want to display uppercase, you can modify the /conf/messages
title=titlecontent=contentpostedat=posted atauthor=authorpost=related posttags=tags Setname=Common nameemail= Emailpassword=passwordfullname=full Nameisadmin=user is admin
。。
Play Framework full implementation of an app (ix)