Play Framework full implementation of an app (ix)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.