Home >Backend Development >XML/RSS Tutorial >PlayFramework completely implements an APP (9)
Add add, delete, modify and check operations
1. Enable CRUD Module
Add in /conf/application.conf
# Import the crud module
module.crud=${play.path}/modules/crud
Add
# Import CRUD routes
* in /conf/routes /admin
public class Posts extends CRUD {
}public class Tags extends CRUD {}public class Users extends CRUD {
}public class Comments extends CRUD {}
may prompt an error: CRUD cannot be parsed to type and running the program will prompt an error
Solution:
Modify conf/dependencies.yml
- play
- play -> crud
Run Shell
> play dependencies
The modules/crud file will be generated under the project. Just restart the project, but compilation will still cause errors. It may be because the crud project is not referenced
3. Create Controller
package controllers;import models.User;
@CRUD.For(User.class)public class AdminUsers extends CRUD {
}
4. Modify the Model and add verification
Take User as an example
public class User extends Model {
@Email
@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 class Post extends Model {
@Required public String title;
@Required public Date postedAt;
@Lob
@Required@MaxSize(10000) public String content;
@Required
@ManyToOne public User author;
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL) Public List
@ManyToMany(cascade = CascadeType.PERSIST) public Set
}
public class Tag extends Model implements Comparable
@Required public String name;
}
@Required public String author;
@Required public Date postedAt;
@Lob
@Required
@ManyToOne
@Required public Post post ;
}
5. The Label name displayed on the page is lowercase, consistent with the field name of the corresponding class. If you want to display uppercase, you can modify /conf/messages
title=Title
content=Content
postedAt= Posted at
author=Author
post=Related post
name=Common name
email=Emailpassword=Password
fullname=Full nameisAdmin=User is admin
The above is the complete PlayFramework Implement the content of an APP (9). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!