Develop play with Eclipse

Source: Internet
Author: User

The premise is that the play has been imported into eclipse, no see this:http://blog.csdn.net/u013372441/article/details/47100129

And then create a few files in the project directory as shown in


Direct code

Application.java

<span style= "FONT-SIZE:18PX;" >package controllers;import play.*;import play.mvc.*;import java.util.*;import models.*;p ublic class Application    Extends Controller {public static void index () {render ();    } public static void login () {render (); } public static void Dologin (String user,string password) {User User1 =user.find ("user=?    And password=? ", User,password). First ();    if (User1!=null) {System.out.println ("success!");    System.out.println (User1.user+user1.password);    String Hello =user1.user;    System.out.println (hello);        Success (hello);    Print the return value of Find here Index ();        Jump to the original index.html page} else{System.out.println ("wrong!");    Login ();    Continue to stay on landing page}} public static void register () {render ();    }//implement register public static void Doregister (String user,string password) {User user2= new user ();    User2.user=user;    User2.password=password;    User2.save ();    else{Register ();    }    public static void Success (String name) {render (name); }}</span>
here's User.java .

<span style= "FONT-SIZE:18PX;" >package models;import javax.persistence.entity;import Play.db.jpa.Model; @Entitypublic class User extends model{ public string user;public string password;} </span>
Then there are a few HTML pages

Index.html

<span style= "FONT-SIZE:18PX;" ><! DOCTYPE html >
login.html

<span style= "font-size:18px;" ><! DOCTYPE html >
register.html

<span style= "FONT-SIZE:18PX;" ><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
success.html

<span style= "FONT-SIZE:18PX;" ><! DOCTYPE html>
Next is the configuration of the routes


<span style= "FONT-SIZE:18PX;" ># routes# This file defines all application Routes (higher priority Routes first) # ~~~~# Home pageget     /                                       applic Ation.indexget/login                                  application.loginget/registerapplication.registerget     /success                                application.success# Ignore favicon requestsget     /favicon.ico                            404# Map static resources from The/app/public Folder to The/public pathget     /public/                                staticdir:public# Catch all*       /{controller}/{action}                  { Controller}. {action}</span>
then the configuration of the database

Find the following interface in application.conf


Here I choose the MySQL database and then I use the username is root, the password is 123456,localhost is the local address no need to change, one is my own database name, replace it with your own

Then run the play run first under CMD

Enter 127.0.0.1:9000 in the browser and you'll see the page.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Develop play with Eclipse

Related Article

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.