- 浏览: 2567435 次
- 性别:
- 来自: 成都
-
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Playframework(6)Java Project and TODO Sample
Create Project
>play new todolist
I choose simple java project.
>cd todolist
>play eclipsify
Make it works in eclipse.
Using the Play Console
>play
play>run
Overview and Preparing the application
Prepare the routes first, and redirect the home page to my working tasks.
The original Action is passing one parameter and send to scala html template
return ok(index.render("You new application is ready"));
The index scala html will template from the main template, pass the title and html to main
@(message: String)
@main("Welcome to Play 2.0"){
@play20.welcome(message)
}
First define our entries in routes
#Tasks
GET /tasks controllers.Application.tasks()
POST /tasks controllers.Application.newTask()
POST /tasks/:id/delete controllers.Application.deleteTask(id: Long)
We can add the action in controllers, and we can return TODO instead of Result at first.
And it will return 501 Not Implemented response
Change the home page to redirect to my tasks
return redirect(routes.Application.tasks());
Prepare the Task model
package models;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import play.data.validation.Constraints.Required;
import play.db.ebean.Model;
@Entity
publicclass Task extends Model{
privatestaticfinallongserialVersionUID = -7161351873652106184L;
@Id
public Long id;
@Required
public String label;
publicstatic Finder<Long,Task> find = new Finder<Long, Task>(
Long.class, Task.class
);
publicstatic List<Task> all(){
returnfind.all();
}
publicstaticvoid create(Task task){
task.save();
}
publicstaticvoid delete(Long id){
find.ref(id).delete();
}
}
We use Ebean, and we use @Required, @Entity in our business model.
The application template
@(tasks: List[Task], taskForm: Form[Task])
@import helper._
@main("Todo List"){
<h1]]>@tasks.size() task(s)</h1>
<ul>
@for(task <- tasks) {
<li>
@task.label
@form(routes.Application.deleteTask(task.id)) {
<input type="submit" value="Delete">
}
</li>
}
</ul>
<h2>Add a new task</h2>
@form(routes.Application.newTask()) {
@inputText(taskForm("label"))
<input type="submit" value="Create">
}
}
We use scala in our template, just use scala edit to open them.
The Task Form and Handling the form submission
In our action, we can get the form value from request
public class Application extends Controller {
static Form<Task> taskForm = form(Task.class);
…snip…
public static Result tasks() {
// to do will return a 501 Not Implemented response
//return to do; Capital it and get rid of the space
return ok(views.html.index.render(Task.all(),taskForm));
//this render method turned red, so I import SCALA 2.9.2, it works
}
publicstatic Result newTask() {
//return to do;
Form<Task> filledForm = taskForm.bindFromRequest();
if(filledForm.hasErrors()){
//return 400 Bad Request if we have errors.
return badRequest(
views.html.index.render(Task.all(),filledForm)
);
}else{
Task.create(filledForm.get());
return redirect(routes.Application.tasks());
}
}
Persist the tasks in a database
Start to enable the database configuration in our application
>vi conf/application.conf
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
ebean.default="models.*"
Deleting Tasks
publicstatic Result deleteTask(Long id) {
//return to do;
Task.delete(id);
return redirect(routes.Application.tasks());
}
Deploying to Heroku
I just ignore this. I do not want to deploy on that server.
Next step I will go on study some other samples. No, I will go on with SCALA then.
References:
http://www.playframework.org/documentation/2.0.4/JavaTodoList
http://sillycat.iteye.com/blog/1750340
http://sillycat.iteye.com/blog/1750947
http://sillycat.iteye.com/blog/1751649
http://sillycat.iteye.com/blog/1752183
http://www.playframework.org/documentation/2.0.4/Samples
http://www.playframework.org/documentation/2.0.4/ScalaHome
http://www.playframework.org/documentation/1.0/gae
Create Project
>play new todolist
I choose simple java project.
>cd todolist
>play eclipsify
Make it works in eclipse.
Using the Play Console
>play
play>run
Overview and Preparing the application
Prepare the routes first, and redirect the home page to my working tasks.
The original Action is passing one parameter and send to scala html template
return ok(index.render("You new application is ready"));
The index scala html will template from the main template, pass the title and html to main
@(message: String)
@main("Welcome to Play 2.0"){
@play20.welcome(message)
}
First define our entries in routes
#Tasks
GET /tasks controllers.Application.tasks()
POST /tasks controllers.Application.newTask()
POST /tasks/:id/delete controllers.Application.deleteTask(id: Long)
We can add the action in controllers, and we can return TODO instead of Result at first.
And it will return 501 Not Implemented response
Change the home page to redirect to my tasks
return redirect(routes.Application.tasks());
Prepare the Task model
package models;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import play.data.validation.Constraints.Required;
import play.db.ebean.Model;
@Entity
publicclass Task extends Model{
privatestaticfinallongserialVersionUID = -7161351873652106184L;
@Id
public Long id;
@Required
public String label;
publicstatic Finder<Long,Task> find = new Finder<Long, Task>(
Long.class, Task.class
);
publicstatic List<Task> all(){
returnfind.all();
}
publicstaticvoid create(Task task){
task.save();
}
publicstaticvoid delete(Long id){
find.ref(id).delete();
}
}
We use Ebean, and we use @Required, @Entity in our business model.
The application template
@(tasks: List[Task], taskForm: Form[Task])
@import helper._
@main("Todo List"){
<h1]]>@tasks.size() task(s)</h1>
<ul>
@for(task <- tasks) {
<li>
@task.label
@form(routes.Application.deleteTask(task.id)) {
<input type="submit" value="Delete">
}
</li>
}
</ul>
<h2>Add a new task</h2>
@form(routes.Application.newTask()) {
@inputText(taskForm("label"))
<input type="submit" value="Create">
}
}
We use scala in our template, just use scala edit to open them.
The Task Form and Handling the form submission
In our action, we can get the form value from request
public class Application extends Controller {
static Form<Task> taskForm = form(Task.class);
…snip…
public static Result tasks() {
// to do will return a 501 Not Implemented response
//return to do; Capital it and get rid of the space
return ok(views.html.index.render(Task.all(),taskForm));
//this render method turned red, so I import SCALA 2.9.2, it works
}
publicstatic Result newTask() {
//return to do;
Form<Task> filledForm = taskForm.bindFromRequest();
if(filledForm.hasErrors()){
//return 400 Bad Request if we have errors.
return badRequest(
views.html.index.render(Task.all(),filledForm)
);
}else{
Task.create(filledForm.get());
return redirect(routes.Application.tasks());
}
}
Persist the tasks in a database
Start to enable the database configuration in our application
>vi conf/application.conf
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
ebean.default="models.*"
Deleting Tasks
publicstatic Result deleteTask(Long id) {
//return to do;
Task.delete(id);
return redirect(routes.Application.tasks());
}
Deploying to Heroku
I just ignore this. I do not want to deploy on that server.
Next step I will go on study some other samples. No, I will go on with SCALA then.
References:
http://www.playframework.org/documentation/2.0.4/JavaTodoList
http://sillycat.iteye.com/blog/1750340
http://sillycat.iteye.com/blog/1750947
http://sillycat.iteye.com/blog/1751649
http://sillycat.iteye.com/blog/1752183
http://www.playframework.org/documentation/2.0.4/Samples
http://www.playframework.org/documentation/2.0.4/ScalaHome
http://www.playframework.org/documentation/1.0/gae
发表评论
-
NodeJS12 and Zlib
2020-04-01 07:44 492NodeJS12 and Zlib It works as ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 351Traefik 2020(1)Introduction and ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 449Private Registry 2020(1)No auth ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 401Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 496NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 438Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 346Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 262GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 463GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 336GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 322Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 330Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 306Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 320Serverless with NodeJS and Tenc ... -
NodeJS MySQL Library and npmjs
2020-02-07 06:21 307NodeJS MySQL Library and npmjs ... -
Python Library 2019(1)requests and aiohttp
2019-12-18 01:12 272Python Library 2019(1)requests ... -
NodeJS Installation 2019
2019-10-20 02:57 586NodeJS Installation 2019 Insta ... -
Monitor Tool 2019(2)Monit on Multiple Instances and Email Alerts
2019-10-18 10:57 279Monitor Tool 2019(2)Monit on Mu ... -
Sqlite Database 2019(1)Sqlite3 Installation and Docker phpsqliteadmin
2019-09-05 11:24 388Sqlite Database 2019(1)Sqlite3 ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 387Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
Play Framework 2.0 是一个开源的Web应用框架,它基于Scala和Java语言,遵循“模式-动作”(Action)架构,提供了一种轻量级、敏捷开发的方式。本篇文章将引导你通过创建一个简单的待办事项(Todo List)应用来了解...
SwiftTodo 是一个基于 iOS 平台的开源项目,它展示了如何使用 Apple 的编程语言 Swift 来构建一个待办事项(Todo)应用。这个项目对于初学者来说是一个很好的学习资源,因为它提供了一个实际应用的完整代码结构,...
为同步github-project-todo-md 在GitHub Project Board <-> Markdown Todo文本之间同步。 视频: : 安装使用安装 ipm install sync-github-project-todo-md配置设置可以从获取的GitHub个人令牌首选项>插件> sync-...
在本Java实战项目中,我们将构建一个简单的ToDo列表应用程序,主要关注任务管理的核心功能,包括添加、编辑、删除和标记任务完成。以下是实现这些功能的关键步骤和知识点: 1. **创建用户界面**: - 使用Java ...
【标题】:“todo-sample,android干净架构示例.zip”指的是一个开源项目,它演示了如何在Android平台上应用“干净架构”设计模式。这个压缩包包含了名为“todo-sample-master”的源代码仓库。 【描述】:“维吉尼亚...
【标题】"java_todo_project" 是一个基于Java编程语言的待办事项(Todo)项目,旨在帮助用户管理和跟踪他们的日常任务。这个项目可能包含了创建一个图形用户界面(GUI)以及与文件系统的交互功能。 【描述】 在...
Android简洁清爽的Todo清单工具是一个非常简洁清爽的清单工具,帮您轻松记录个人计划。本App的特色就是简洁,让人一目了然,在交互上让人体会到视觉上的舒适感。固定的4种清单分类在顶部可直接切换列表。
eventuate-examples-java-spring-todo-list, 使用Eventuate构建的Java和 Spring Boot Todo列表应用程序 待办事项列表示例应用程序it演示如何使用平台编写具有 microservices体系结构的应用程序,使用事件源Sourcing...
(todo, windows phone support) Learning Mobile C Slack instance! UIKonf 2014 CppCon 2014 - A Deep Dive Into Two Cross-Platform Mobile Apps Written in C CppCon 2014 - Practical Cross-Platform Mobile ...
【标题】"Todo-master"指的是一个开源的Todo应用的源代码项目,主要针对"TODO网站源码"和"TOdo源码"。这个项目可能是为了实现一个轻量级的任务管理工具,帮助用户方便地创建、管理和跟踪待办事项。"android"标签表明...
Framework基础上搭建的一个Java基础开发平台,以Spring MVC为模型视图控制器,MyBatis为数据访问层, Apache Shiro为权限授权层,Ehcahe对常用数据进行缓存,Activit为工作流引擎。是JavaEE界的最佳整合。 JeeSite...
启动说明 准备 安装 下载或分叉 运行服务 转到终端中项目的根文件夹 运行sbt run 在浏览器中转到localhost:9000,然后单击“立即应用此脚本!”。 在您的机器上创建数据库( ~/tasks )
通过运行 `composer create-project --prefer-dist laravel/laravel laravel5-sample-todo` 命令,可以创建一个新的 Laravel 5.1 项目。然后,配置 `.env` 文件以连接到你的数据库,并执行 `php artisan migrate` ...
SitePoint.Learn.Angular.Build.a.Todo.App angular构建todo应用 2018年6月sitePoint最新版 epub格式
todo-backend-springboot2-java12 SpringBoot2.2.0 和 Java 12 的 Todo 后端 这是 Todo 后端的一个实现: 这是来自: 存储库中没有测试。 您可以测试在本地运行服务并直接在此处运行规范的行为: ...
inheritConstruct_6.java 构造器继承示例6 inheritor.java 子类覆盖父类示例 inPack.java 包示例 LotsOfColors.java 定义一个子接口 matching.java 重载解析示例 notInPack.java 用前缀引用包中的类 onlyShow...
【Java Todo List Manager - 开源应用详解】 Java Todo List Manager 是一个使用Java技术构建的开源Web应用程序,专门设计用于管理个人或团队的待办事项。它允许用户创建、编辑和跟踪任务,同时还支持任务列表的...
Purchase Todo.txt on Google Play, the Amazon Appstore, or download and compile the source code. This app is in active development and there are several known bugs and todo items. Using Todo.txt for ...
【标题】"Todo-app:用Java开发的每个人的应用"揭示了这个项目是一个使用Java编程语言构建的任务管理应用程序。这类应用通常允许用户创建、编辑、跟踪和管理待办事项,是提高个人生产力和组织效率的工具。 【描述】...
【标题】"java-toDoList-project" 是一个基于Java编程语言开发的待办事项列表(To-Do List)项目。这个项目旨在实现一个简单的任务管理工具,帮助用户组织和跟踪日常任务,提升工作效率。 【描述】"去做 java-...