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 databaseFind 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