Play Framework implements a complete APP (2), frameworkapp

Source: Internet
Author: User

Play Framework implements a complete APP (2), frameworkapp

 

1. Develop DataModel

Create User. java under app \ moders

package models;import java.util.*;import javax.persistence.*;import play.db.jpa.*;@Entitypublic 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 the ID is a JPA entity inherited fromPlay. db. jpa. Model, Provides JPA implementation

Class fields are automatically mapped to the DB table. The default value is "User". If you want to modify the value, add a label to the class"@ Table (name = "blog_user ")"

 

2. Test

Run

>play test yape

Or run Test Yet Another Blog Engine in Eclipse.

Access http: // localhost: 9000/@ tests to enter the test mode.

Select Test and Start for execution. If the execution succeeds, it is marked as green. If the execution fails, a prompt is displayed.

 

3. Write Test Cases

Modify/Test/BasicTest. java

@Testpublic 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); }

Create a User, search for the User, and assert

The User inherits from the Model and provides methods such as save \ find.

 

User. java add connect Method

public static User connect(String email, String passowrd) {return find("byEmailAndPassword", email, passowrd).first();}

  

Add Test Cases

@Testpublic 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", "####"));}

  

 

 

..

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.