- 浏览: 2539039 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
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(16)RESTful Example
I used Playframework for sometime for scala/java. This time, I just need to upgrade the play framework version and write some RESTful API I guess to help my friends. Here are some tips:
Mysql Configuration
https://www.playframework.com/documentation/2.3.8/JavaDatabase
play framework is using boneCP I guess, not dbcp or c3p0. That is its own database connection pool which is claimed better. Here is some CONF example:
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/playrest"
db.default.user=playrest
db.default.password="playrest"
db.default.logStatements=true
db.test.driver=com.mysql.jdbc.Driver
db.test.url="jdbc:mysql://localhost/test"
db.test.user=tester
db.test.password="tester"
db.test.logStatements=true
DB Migration
http://flywaydb.org/
http://sillycat.iteye.com/blog/2022462
I used flyway this time, because I am using flyway in other project. I can keep using flyway in all the projects, scala, java and etc.
One core class BaseDAO.java is as follow:
package models;
import org.flywaydb.core.Flyway;
import play.db.DB;
/**
* Created by carl on 4/1/15.
*/
public class BaseDAO {
private static Flyway initFlyway(){
Flyway flyway = new Flyway();
flyway.setDataSource(DB.getDataSource("test"));
return flyway;
}
public static void create(){
Flyway flyway = initFlyway();
flyway.migrate();
}
public static void clean(){
Flyway flyway = initFlyway();
flyway.clean();
}
}
Bean Mapper
http://stackoverflow.com/questions/15322567/how-to-transform-dbutils-resultset-into-javabeans-composited-from-more-domain-ob
I am using native SQL in DAO layer, I am not a fan of hibernate or Ebean. I prefer to directly use SQL there with the help of DBUtils. Then if the column name and property name are different, then I need to write some customer handler for bean mapping.
package models;
import java.util.Date;
public class Task {
public Long id ;
public String name;
public String desn;
public Date startDate;
public Date endDate;
}
package models;
import org.apache.commons.dbutils.BasicRowProcessor;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by carl on 4/1/15.
*/
public class TaskRowProcessor extends BasicRowProcessor {
@Override
public Object toBean(ResultSet rs, Class type) throws SQLException {
Task item = new Task();
item.id = rs.getLong("ID");
item.name = rs.getString("NAME");
item.desn = rs.getString("DESN");
item.startDate = rs.getTimestamp("START_DATE");
item.endDate = rs.getTimestamp("END_DATE");
return item;
}
@Override
public <T> List<T> toBeanList(ResultSet rs, Class<T> type) throws SQLException {
List newlist = new ArrayList();
try {
while (rs.next()) {
newlist.add(toBean(rs, type));
}
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
return newlist;
}
}
Using the mapping in DAO class
item = runner.query(sql,new BeanHandler<Task>(Task.class, new TaskRowProcessor()),id);
How to Do Logging
https://www.playframework.com/documentation/2.3.8/JavaLogging
https://www.playframework.com/documentation/2.3.8/ProductionConfiguration
https://www.playframework.com/documentation/2.3.8/SettingsLogger
How to Config
https://www.playframework.com/documentation/2.3.8/ProductionConfiguration
Load the config at runtime, Play will check the con directory itself
>/path/to/bin/project-name -Dconfig.resource=application-local.conf
Play will load the file from directory
>/path/to/bin/project-name -Dconfig.file=/etc/conf/application-local.conf
Play will load the content from remote
>/path/to/bin/project-name -Dconfig.url=http://conf.sillycat.com/conf/application-local.conf
How to Run the Test class
https://www.playframework.com/documentation/2.3.8/JavaTest
https://www.playframework.com/documentation/2.3.8/JavaFunctionalTest
> activator "testOnly models.*"
Or
Entry the activator env first
> [sillycat-playrest] $ testOnly models.TaskDAOTest
The sample project is named sillycat-playrest.
References:
java8
http://www.jooq.org/java-8-and-sql
playframework doc
https://www.playframework.com/documentation/2.3.x/JavaDatabase
dbutils
http://tianyongwei.logdown.com/posts/243610-commons-dbutils
http://aofengblog.blog.163.com/blog/static/63170212014510105657292/
http://wallimn.iteye.com/blog/1606930
http://commons.apache.org/proper/commons-dbutils/examples.html
writing test
https://www.playframework.com/documentation/2.3.8/JavaTest
I used Playframework for sometime for scala/java. This time, I just need to upgrade the play framework version and write some RESTful API I guess to help my friends. Here are some tips:
Mysql Configuration
https://www.playframework.com/documentation/2.3.8/JavaDatabase
play framework is using boneCP I guess, not dbcp or c3p0. That is its own database connection pool which is claimed better. Here is some CONF example:
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/playrest"
db.default.user=playrest
db.default.password="playrest"
db.default.logStatements=true
db.test.driver=com.mysql.jdbc.Driver
db.test.url="jdbc:mysql://localhost/test"
db.test.user=tester
db.test.password="tester"
db.test.logStatements=true
DB Migration
http://flywaydb.org/
http://sillycat.iteye.com/blog/2022462
I used flyway this time, because I am using flyway in other project. I can keep using flyway in all the projects, scala, java and etc.
One core class BaseDAO.java is as follow:
package models;
import org.flywaydb.core.Flyway;
import play.db.DB;
/**
* Created by carl on 4/1/15.
*/
public class BaseDAO {
private static Flyway initFlyway(){
Flyway flyway = new Flyway();
flyway.setDataSource(DB.getDataSource("test"));
return flyway;
}
public static void create(){
Flyway flyway = initFlyway();
flyway.migrate();
}
public static void clean(){
Flyway flyway = initFlyway();
flyway.clean();
}
}
Bean Mapper
http://stackoverflow.com/questions/15322567/how-to-transform-dbutils-resultset-into-javabeans-composited-from-more-domain-ob
I am using native SQL in DAO layer, I am not a fan of hibernate or Ebean. I prefer to directly use SQL there with the help of DBUtils. Then if the column name and property name are different, then I need to write some customer handler for bean mapping.
package models;
import java.util.Date;
public class Task {
public Long id ;
public String name;
public String desn;
public Date startDate;
public Date endDate;
}
package models;
import org.apache.commons.dbutils.BasicRowProcessor;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by carl on 4/1/15.
*/
public class TaskRowProcessor extends BasicRowProcessor {
@Override
public Object toBean(ResultSet rs, Class type) throws SQLException {
Task item = new Task();
item.id = rs.getLong("ID");
item.name = rs.getString("NAME");
item.desn = rs.getString("DESN");
item.startDate = rs.getTimestamp("START_DATE");
item.endDate = rs.getTimestamp("END_DATE");
return item;
}
@Override
public <T> List<T> toBeanList(ResultSet rs, Class<T> type) throws SQLException {
List newlist = new ArrayList();
try {
while (rs.next()) {
newlist.add(toBean(rs, type));
}
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
return newlist;
}
}
Using the mapping in DAO class
item = runner.query(sql,new BeanHandler<Task>(Task.class, new TaskRowProcessor()),id);
How to Do Logging
https://www.playframework.com/documentation/2.3.8/JavaLogging
https://www.playframework.com/documentation/2.3.8/ProductionConfiguration
https://www.playframework.com/documentation/2.3.8/SettingsLogger
How to Config
https://www.playframework.com/documentation/2.3.8/ProductionConfiguration
Load the config at runtime, Play will check the con directory itself
>/path/to/bin/project-name -Dconfig.resource=application-local.conf
Play will load the file from directory
>/path/to/bin/project-name -Dconfig.file=/etc/conf/application-local.conf
Play will load the content from remote
>/path/to/bin/project-name -Dconfig.url=http://conf.sillycat.com/conf/application-local.conf
How to Run the Test class
https://www.playframework.com/documentation/2.3.8/JavaTest
https://www.playframework.com/documentation/2.3.8/JavaFunctionalTest
> activator "testOnly models.*"
Or
Entry the activator env first
> [sillycat-playrest] $ testOnly models.TaskDAOTest
The sample project is named sillycat-playrest.
References:
java8
http://www.jooq.org/java-8-and-sql
playframework doc
https://www.playframework.com/documentation/2.3.x/JavaDatabase
dbutils
http://tianyongwei.logdown.com/posts/243610-commons-dbutils
http://aofengblog.blog.163.com/blog/static/63170212014510105657292/
http://wallimn.iteye.com/blog/1606930
http://commons.apache.org/proper/commons-dbutils/examples.html
writing test
https://www.playframework.com/documentation/2.3.8/JavaTest
发表评论
-
Stop Update Here
2020-04-28 09:00 310I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 465NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 361Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 362Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 328Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 419Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 428Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 364Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 444VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 376Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 462NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 413Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 330Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 242GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 443GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 320GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 306Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 310Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 284Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 302Serverless with NodeJS and Tenc ...
相关推荐
"playframework"和"WebappJava"则明确指出使用了Play Framework和Java来构建Web应用。 在"play-java-rest-api-example-2.7.x"这个压缩包中,我们可能找到以下关键组件: 1. **项目结构**:遵循Play Framework的...
总的来说,`play-scala-forms-example`项目为我们提供了一个很好的学习平台,展示了如何在Play Framework中使用Scala处理表单,包括表单定义、数据绑定、验证、重定向等关键环节。通过这个例子,开发者可以更好地...
- **playframework**:明确了框架是Play Framework。 - **WebappJava**:再次确认此项目是用Java编写的Web应用程序。 **文件名称列表分析** 由于只给出了 "play-java-jpa-example-2.7.x" 这个文件名,我们可以推断...
6. **playframework** - 标签核心,表明该项目与Play Framework框架相关。 7. **WebappJava** - 强调此Web应用是用Java语言编写的。 **文件名称列表解析:** 由于只给出了"play-java-fileupload-example-2.7.x",...
6. "playframework" - 关键技术,即Play Framework,用于构建现代、反应式的Web应用。 7. "WebappJavaScript" - 提及JavaScript,可能意味着项目中包含了与前端交互的JavaScript代码,可能用于处理接收到的Comet或...
在本篇文章中,我们将深入探讨`play-scala-rest-api-example`,这是一个展示如何使用Play Framework和Scala构建RESTful API的实例应用。 ### REST API 基础 REST(Representational State Transfer)是一种网络...
在Java世界中,Play Framework提供了一种现代、简洁的方式来构建RESTful API和Web应用。它支持Java 8及更高版本,并利用Scala和Java互操作性,使得开发过程更加高效。框架内集成了许多功能,如路由、模板引擎、依赖...
**Play-Slick3-Example:探索Scala与Slick在Play Framework中的应用** Play Framework是一个流行的、开源的Web应用框架,它以Scala和Java为后端语言,提供了快速、简洁和可测试的开发环境。Slick是Scala的一个强大...
7. **playframework** - 指的是Play框架,表明项目使用了这个框架。 8. **WebappJava** - 指出这是Java语言编写的Web应用。 **压缩包子文件的文件名称列表:** "play-java-ebean-example-2.7.x" 这个文件名可能代表...
**Play Framework与WebGoat简介** Play Framework是一个开源的、基于Java和Scala的Web应用框架,它遵循模型-视图-控制器(MVC)架构模式,致力于提供快速、直观且可测试的开发体验。Play Framework以其简洁的API、...
2. **Play Framework**: Play是基于Java和Scala的开源Web应用框架,遵循MVC(Model-View-Controller)架构模式,支持异步I/O和热加载,适合开发RESTful API。Play与Scala的集成使得开发者可以利用Scala的强大功能来...
6. **Web框架**:项目可能使用Spring Boot或Play Framework等Java Web框架,以快速开发RESTful API或Web界面。这些框架提供了处理HTTP请求、路由、模板引擎等功能。 7. **测试**:Java项目通常包含测试代码,可能在...