Play Framework 完整实现一个APP(二)
1.开发DataModel
在app\moders 下新建User.java
package models; import java.util.*;
import javax.persistence.*;
import play.db.jpa.*; @Entity
public class User extends Model {
public String email;
public String password;
public String fullname;
public String isAdmin; public User(String email, String password, String fullname) {
this.email = email;
this.password = password;
this.fullname = fullname;
}
}
@Entity标识是一个JPA entity,继承自play.db.jpa.Model,提供了JPA实现
类的字段,会自动映射到DB表中,默认表明是"User",如果要修改表明,在类上添加标签"@Table(name="blog_user")"
2.测试
运行
>play test yape
或在Eclipse中运行,Test Yet Another Blog Engine
访问 http://localhost:9000/@tests, 进入测试模式

选择Test, Start执行,成功会标记为绿色,失败会有提示
3.写测试用例
修改 /test/BasicTest.java
@Test
public void createAndRetrieveUser() {
//Create a new user and save it
new User("alex@gmail.com", "####", "Alex").save(); //Retrieve the user with email address
User user = User.find("byEmail", "alex@gmail.com").first(); //Test
assertNotNull(user);
assertEquals("Alex", user.fullname);
}
创建User,查找User,进行断言
User继承自Model,提供了save\find等方法
User.java添加connect方法
public static User connect(String email, String passowrd) {
return find("byEmailAndPassword", email, passowrd).first();
}
添加测试用例
@Test
public void tryConnectAsUser() {
// Create a new user and save it
new User("bob@gmail.com", "####", "Bob").save(); // Test
assertNotNull(User.connect("bob@gmail.com", "####"));
assertNull(User.connect("bob@gmail.com", "$$$$"));
assertNull(User.connect("tom@gmail.com", "####"));
}
..
Play Framework 完整实现一个APP(二)的更多相关文章
- Play Framework 完整实现一个APP(十二)
1.定制CRUD管理页面 > play crud:ov --layout 替换生成文件内容 app/views/CRUD/layout.html #{extends 'admin.html' / ...
- Play Framework 完整实现一个APP(十一)
添加权限控制 1.导入Secure module,该模块提供了一个controllers.Secure控制器. /conf/application.conf # Import the secure m ...
- Play Framework 完整实现一个APP(五)
程序以及基本可用了,需要继续完善页面 1.创建页面模板 创建文件 app/views/tags/display.html *{ Display a post in one of these modes ...
- Play Framework 完整实现一个APP(十四)
添加测试 ApplicationTest.java @Test public void testAdminSecurity() { Response response = GET("/adm ...
- Play Framework 完整实现一个APP(十三)
添加用户编辑区 1.修改Admin.index() public static void index() { List<Post> posts = Post.find("auth ...
- Play Framework 完整实现一个APP(十)
1.定制Comment列表 新增加Comment list页面,执行命令行 > play crud:ov --template Comments/list 会生成/app/views/Comme ...
- Play Framework 完整实现一个APP(九)
添加增删改查操作 1.开启CRUD Module 在/conf/application.conf 中添加 # Import the crud module module.crud=${play.pat ...
- Play Framework 完整实现一个APP(八)
创建Tag标签 1.创建Model @Entity @Table(name = "blog_tag") public class Tag extends Model impleme ...
- Play Framework 完整实现一个APP(六)
需要为Blog添加 查看和发表评论的功能 1.创建查看功能 Application.java中添加 show() 方法 public static void show(Long id) { Post ...
随机推荐
- Web API应用支持HTTPS的经验总结
在我前面介绍的WebAPI文章里面,介绍了WebAPI的架构设计方面的内容,其中提出了现在流行的WebAPI优先的路线,这种也是我们开发多应用(APP.微信.微网站.商城.以及Winform等方面的整 ...
- HoverTree.Model.ArticleSelect类的作用
ArticleSelect类在命名空间HoverTree.Model中可以认为是文章查询条件类,用于存放查询文章时的条件,例如HvtId就是文章的id.HvtIsShow就是文章的显示属性,当为-1是 ...
- ASP.NET Core Web API 开发-RESTful API实现
ASP.NET Core Web API 开发-RESTful API实现 REST 介绍: 符合REST设计风格的Web API称为RESTful API. 具象状态传输(英文:Representa ...
- WinForm三级联动
窗体中方三个combobox Form1 中的代码 AreaDataBind函数 new chinaData().Select()函数 找到combobox属性里面的事件 selectedindexc ...
- 孙鑫MFC学习笔记7:对话框编程(上)
1.DoModal创建模态对话框 2.Create创建非模态对话框(需要用ShowWindow显示出来) 模态:对话框显示,程序会暂停,直到对话框关闭 非模态:对话框显示,程序继续执行 3.对于模态对 ...
- Spring发展历程总结
目前很多公司的架构,从Struts2迁移到了SpringMVC.你有想过为什么不使用Servlet+JSP来构建Java web项目,而是采用SpringMVC呢? 既然这样,我们从源头说起.Stru ...
- CentOS minimal网络设置
CentOS minimal版本默认不启动网络,所以要自己配置. 配置过程: 编辑配置文件: vi /etc/sysconfig/network-script/ifcfg-eth0 需要更改两项 NM ...
- Dynamics.js - 创建逼真的物理动画的 JS 库
Dynamics.js 是一个用来创建物理动画 JavaScript 库.你只需要把dynamics.js引入你的页面,然后就可以激活任何 DOM 元素的 CSS 属性动画,也可以用户 SVG 属性. ...
- FROONT – 超棒的可视化响应式网页设计工具
FROONT 是一个基于 Web 的设计工具,在浏览器中运行,使得各类可视化设计的人员都能进行响应式的网页设计,即使是那些没有任何编码技能的设计师.FROONT 使得响应式网页设计能够可视化操作,能够 ...
- easyui1.3.2中使用1.3.6或1.4.x的calendar
首先在1.3.2中calendar控件不支持日历某天的颜色进行改变,和自定义回调函数 Name Type Description Default width number The width of c ...