3,422
社区成员
发帖
与我相关
我的任务
分享
package controllers;
import model.Task;
import play.data.Form;
import play.mvc.*;
public class Application extends Controller {
static Form<Task> taskForm = Form.form(Task.class);
public static Result index() {
//return ok(index.render("Your new application is ready."));
return redirect(routes.Application.tasks());
}
public static Result tasks(){
return ok(views.html.index.render(Task.all(),taskForm));
}
public static Result newTask(){
Form<Task> filledForm = taskForm.bindFromRequest();
if(filledForm.hasErrors()){
return badRequest(
views.html.index.render(Task.all(),filledForm)
);
}else{
Task.create(filledForm.get());
return redirect(routes.Application.tasks());
}
}
public static Result deleteTask(Integer id){
Task.delete(id);
return redirect(routes.Application.tasks());
}
}
package model;
import java.util.List;
import javax.persistence.*;
import play.data.validation.Constraints.*;
import play.db.ebean.*;
@Entity
@Table(name="task")
public class Task extends Model{
private static final long serialVersionUID = 1L;
@Id
public Integer id;
@Required
public String label;
public static Finder<Integer,Task> find = new Finder<Integer,Task>(Integer.class,Task.class);
public static List<Task> all(){
return find.all();
}
public static void create(Task task){
task.save();
}
public static void delete(Integer id){
find.ref(id).delete();
}
}
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / controllers.Application.index()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
# Tasks
GET /tasks controllers.Application.tasks()
POST /tasks controllers.Application.newTask()
POST /tasks/:id/delete controllers.Application.deleteTask(id: Integer)
# This is the main configuration file for the application.
# ~~~~~
# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
application.secret="Xte]]5>ggfU1@MCpV9]HP7yhB?@OwH4yU>ZkosmNgyEnLr18lGIl2::@3;rpraYM"
# The application languages
# ~~~~~
application.langs="en"
# Global object class
# ~~~~~
# Define the Global object class for this application.
# Default to Global in the root package.
# application.global=Global
# Router
# ~~~~~
# Define the Router object to use for this application.
# This router will be looked up first when the application is starting up,
# so make sure this is the entry point.
# Furthermore, it's assumed your route file is named properly.
# So for an application router like `conf/my.application.Router`,
# you may need to define a router file `my.application.routes`.
# Default to Routes in the root package (and `conf/routes`)
# application.router=my.application.Routes
# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://127.0.0.1:3306/play"
db.default.user=root
db.default.password="123456"
#
# You can expose this datasource via JNDI if needed (Useful for JPA)
# db.default.jndiName=DefaultDS
# Evolutions
# ~~~~~
# You can disable evolutions if needed
evolutionplugin=disabled
# Ebean configuration
# ~~~~~
# You can declare as many Ebean servers as you want.
# By convention, the default server is named `default`
#
ebean.default="models.*"
# Logger
# ~~~~~
# You can also configure logback (http://logback.qos.ch/),
# by providing an application-logger.xml file in the conf directory.
# Root logger:
logger.root=ERROR
# Logger used by the framework:
logger.play=INFO
# Logger provided to your application:
logger.application=DEBUG