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 ...
随机推荐
- MySQL MHA配置常见问题
MHA在MySQL数据库中被广泛使用,它小巧易用,功能强大,实现了基于MySQL replication架构的自手动主从故障转移,从库重定向到主库并自动同步.尽管如此,在部署配置的过程中,由于疏忽总难 ...
- SqlServer中的自增的ID的最后的值:
SqlServer中的自增的ID的最后的值: SELECT SCOPE_IDENTITY() --返回插入到同一作用域中的 IDENTITY 列内的最后一个 IDENTITY 值.SELECT @@I ...
- Base64 字符串转图片 问题整理汇总
前言 最近碰到了一些base64字符串转图片的开发任务,开始觉得没啥难度,但随着开发的进展还是发现有些东西需要记录下. Base64 转二进制 这个在net有现有方法调用: Convert.FromB ...
- luogg_java学习_02_基本语法
本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! 关键字 定义:被java语言赋予了特殊含义,用作专门用 ...
- NoSQL入门概述
入门概述 1 NoSQL是什么? NoSQL(NoSQL = Not Only SQL ),意即"不仅仅是SQL",泛指非关系型的数据库.随着互联网web2.0网站的兴起,传统的关 ...
- 框架SpringMVC笔记系列 二 传值
主题:SpringMVC(第一节中再回顾复习一次) 学习资料参考网址: 1.http://www.icoolxue.com 2.http://haohaoxuexi.iteye.com/blog/13 ...
- 性能测试学习之三—— PV->TPS转换模型&TPS波动模型
PV->TPS转换模型 由上一篇“性能测试学习之二 ——性能测试模型(PV计算模型)“ 得知 TPS = ( (80%*总PV)/(24*60*60*(T/24)))/服务器数量 转换需要注意: ...
- 【干货分享】Node.js 中文学习资料和教程导航
这篇文章来自 Github 上的一位开发者收集整理的 Node.js 中文学习资料和教程导航.Node 是一个服务器端 JavaScript 解释器,它将改变服务器应该如何工作的概念,它的目标是帮助程 ...
- css选择器中:first-child与:first-of-type的区别
:first-child选择器是css2中定义的选择器,从字面意思上来看也很好理解,就是第一个子元素.比如有段代码: p:first-child 匹配到的是p元素,因为p元素是div的第一个子元素: ...
- ThinkPHP3.2 G函数代码及 使用方法
ThinkPHP3.2 G函数代码及 使用方法 代码: // 内存是否可调用 define('MEMORY_LIMIT_ON',function_exists('memory_get_usage')) ...