- 浏览: 2492558 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
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 435NodeJS12 and Zlib It works as ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 297Traefik 2020(1)Introduction and ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 380Private Registry 2020(1)No auth ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 342Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 424NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 369Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 300Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 214GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 399GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 283GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 274Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 268Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 256Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 244Serverless with NodeJS and Tenc ... -
NodeJS MySQL Library and npmjs
2020-02-07 06:21 240NodeJS MySQL Library and npmjs ... -
Python Library 2019(1)requests and aiohttp
2019-12-18 01:12 229Python Library 2019(1)requests ... -
NodeJS Installation 2019
2019-10-20 02:57 527NodeJS Installation 2019 Insta ... -
Monitor Tool 2019(2)Monit on Multiple Instances and Email Alerts
2019-10-18 10:57 232Monitor Tool 2019(2)Monit on Mu ... -
Sqlite Database 2019(1)Sqlite3 Installation and Docker phpsqliteadmin
2019-09-05 11:24 325Sqlite Database 2019(1)Sqlite3 ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 325Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
SwiftTodo, [iOS] a sample project of todo app using swift
在这篇Java实战博客中,我将向您展示如何使用Java编程语言创建一个简单的ToDo列表应用程序。我们将从创建用户界面开始,然后逐步实现不同的任务管理功能。在整个过程中,我将提供清晰的思路和Java代码示例,以确保您...
为同步github-project-todo-md 在GitHub Project Board <-> Markdown Todo文本之间同步。 视频: : 安装使用安装 ipm install sync-github-project-todo-md配置设置可以从获取的GitHub个人令牌首选项>插件> sync-...
java_todo_project 要做的事情: 图形用户界面 职能 文件处理
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 ...
xamarin forms todo sample
启动说明 准备 安装 下载或分叉 运行服务 转到终端中项目的根文件夹 运行sbt run 在浏览器中转到localhost:9000,然后单击“立即应用此脚本!”。 在您的机器上创建数据库( ~/tasks )
SitePoint.Learn.Angular.Build.a.Todo.App angular构建todo应用 2018年6月sitePoint最新版 epub格式
Laravel开发-laravel5-sample-todo Laravel 5.1示例代码。
todo-backend-springboot2-java12 SpringBoot2.2.0 和 Java 12 的 Todo 后端 这是 Todo 后端的一个实现: 这是来自: 存储库中没有测试。 您可以测试在本地运行服务并直接在此处运行规范的行为: ...
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 ...
inheritConstruct_6.java 构造器继承示例6 inheritor.java 子类覆盖父类示例 inPack.java 包示例 LotsOfColors.java 定义一个子接口 matching.java 重载解析示例 notInPack.java 用前缀引用包中的类 onlyShow...
odin-project-todo-list:待办事项列表
简洁清爽的Todo清单源码,一个非常简洁清爽的清单工具,帮您轻松记录个人计划。
Framework基础上搭建的一个Java基础开发平台,以Spring MVC为模型视图控制器,MyBatis为数据访问层, Apache Shiro为权限授权层,Ehcahe对常用数据进行缓存,Activit为工作流引擎。是JavaEE界的最佳整合。 JeeSite...
##Run Java 8 需要安装###Dev Server ./gradlew server ###在监视模式下测试服务器(需要firefox) ./gradlew testJS -Pwatch ###把它放在一起(自定义任务) ./gradlew putEverythingTogether ##JS 概述 (src...
Flutter实现的简单Todo应用程序.zip,A Simple Todo app design in Flutter to ... You can add a project, labels, and due-date to your task also you can sort your task on the basis of project, label, and dates
大学期间学习安卓做的一个小程序,当时todo计划清单类软件比较火爆,自己简单实现了一些功能,没有使用数据库。等有时间了在修改。