PlayFramework completely implements an APP (9)

黄舟
Release: 2016-12-23 16:46:46
Original
1464 people have browsed it

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

/app/controllers

import play.*;import play.mvc.*;

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

require:

- 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 {

}PlayFramework completely implements an APP (9)

4. Modify the Model and add verification

Take User as an example

public class User 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 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 comments ;

@ManyToMany(cascade = CascadeType.PERSIST) public Set tags;
}




public class Tag extends Model implements Comparable {

@Required public String name;
}

public class Comment 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. If you want to display uppercase, you can modify /conf/messages

title=Title
content=Content
postedAt= Posted at
author=Author
post=Related post

tags=Tags set

name=Common name

email=Email

password=Password

fullname=Full name

isAdmin=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)!




Related labels:
app
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template