•   欢迎来到21NN网.
  •   请记住本站网址www.21nn.cn

PlayFramework完全完成一个APP(九)【XML教程】,PlayFramework,APP

摘要: 增加增编削查操纵1.开启CRUDModule在/conf/application.conf中增加#Importthecrudmodulemodule.crud=${p...
增加增编削查操纵

1.开启CRUD Module

在/conf/application.conf 中增加

# Import the crud module
module.crud=${play.path}/modules/crud

  

在/conf/routes 中增加

# Import CRUD routes
* /admin module:crud

  

须要重启Server,导入CRUD Module

2.增加控制器

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

可能会提醒毛病: CRUD 没法剖析为范例 而且运转顺序会提醒毛病

解决办法:

修正 conf/dependencies.yml

require:
- play
- play -> crud

  

运转Shell

> play dependencies

  

工程下会生成 modules/crud 文件,重新启动工程即可,然则编译照样会失足,多是没有援用crud工程的缘由

3.建立Controller

package controllers;import models.User;

@CRUD.For(User.class)public class AdminUsers extends CRUD {

}

4.修正Model,增加考证

以User为例

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;
}
}

进入http://localhost:9000/admin/ 挑选add user进入 User Form举行测试

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<Comment> comments;

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

public class Tag extends Model implements Comparable<Tag> {

@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.页面上显现的Label名字是小写,与对应类的字段名一致,假如想显现大写,能够修正/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

以上就是PlayFramework完全完成一个APP(九)的内容,更多相关内容请关注ki4网(www.ki4.cn)!

分享到:

发表评论

评论列表

还没有评论,快来说点什么吧~

公众号二维码

微信公众号