1.開發DataModel
在appmoders 下新建User.java
package models;
import java.util.*;
import javax.persistence.*;
public class User extends Model {
public String email;
public String passWord;
public String fullname;
public String isAdmin;
public User(String email, StringString passmail, this.password = password;
this.fullname = fullname;
}
}
@Entity標識是一個JPA entity,繼承自play.db.jpa.Model,提供了JPA實現
類的字段,會自動類對應到DB表中,預設表示是"User",如果要修改表明,在類別上新增標籤"@Table(name="blog_user")"
或在Eclipse中運行,Test Yet Another Blog Engine
訪問 http://localhost:9000/@tests,進入測試模式
3.寫測試案例
修改 /test/BasicTest.java
public void createAndRetrievesUser() {c @Gmail.com", "####", "Alex").save();
//Retrieve the user with email address
User user = User.find("byEEmail", "alex@mail.com ").first();//Test
assertNotNull(user);
assertEquals("Alex", user.fullname);尋找提供了savefind等方法
User.java加入connect方法
public static User connect(String email, String passowrd) {
return find("byEmailAndword", egmail, passowrd);
新增測試案例
@Test
public void tryConnectAsUser() {
// Create a new user and save it
new User("bob@b"#" .save();// Test
assertNotNull(User.connect("bob@gmail.com", "####asser));; $$$$"));
assertNull(User.connect("tom@gmail.com", "####"));}
『 完整實現一個APP(二)的內容,更多相關內容請關注PHP中文網(www.php.cn)!