Play Framework full implementation of an app (ii)

Source: Internet
Author: User
<span id="Label3"></p><p><p></p></p><p><p>1. Development Datamodel</p></p><p><p>Create a new User.java under App\moders</p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;">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, S Tring password, String Fullname) {this.email = Email;this.password = Password;this.fullname = fullname;}}</pre></pre><p><p>The @Entity identity is a JPA entity that inherits from <strong>Play.db.jpa.Model</strong>and provides a JPA implementation</p></p><p><p>Class is automatically mapped to the DB table, which is indicated by default as "User", and if you want to modify it, add the label "<strong>@Table (name=" blog_user ")</strong>to the class.</p></p><p><p></p></p><p><p>2. testing</p></p><p><p>Run</p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;">>play Test Yape</pre></pre><p><p>or run in eclipse, Test yet another Blog Engine</p></p><p><p>Access http://localhost:9000/@tests, Enter test mode</p></p><p><p></p></p><p><p>Select test, start execution, success will be marked green, failure will prompt</p></p><p><p></p></p><p><p>3. Write test Cases</p></p><p><p>Modify <strong>/test/basictest.java</strong></p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;">@Testpublic void Createandretrieveuser () { //create A new user and save it new user ("[email protected]", "# # #", " Alex "). Save (); Retrieve the user with email address user user = User.find ("byemail", "[email protected]"). First (); Test assertnotnull (user); Assertequals ("Alex", user.fullname); }</pre></pre><p><p>Create user, find user, make assertions</p></p><p><p>User inherits from model, provides methods such as Save\find</p></p><p><p></p></p><p><p>User.java Adding the Connect method</p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;">public static User Connect (string email, string passowrd) {return find ("byemailandpassword", email, passowrd). first ();}</pre></pre><p><p>  </p></p><p><p>Adding Test Cases</p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;">@Testpublic void Tryconnectasuser () { //Create A new user and save it new user ("[email protected]", "# # #", "Bob" ). Save (); Test assertnotnull (user.connect ("[email protected]", "# # #")); Assertnull (user.connect ("[email protected]", "$ $")); Assertnull (user.connect ("[email protected]", "# # #]);}</pre></pre><p><p>  </p></p><p><p></p></p><p><p></p></p><p><p>..</p></p><p><p>Play Framework full implementation of an app (ii)</p></p></span>

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.