SlideShare uma empresa Scribd logo
1 de 13
Baixar para ler offline
Quick bootstrap into
PlayFramework (2.1.x)

Łukasz Wójcik
First step
● Download PlayFramework from www.
playframework.com/download
● Add corresponding path to PATH
● Check if it works calling

>play help
Creating and running an Application
Navigate to your projects directory, and type
>play new application-name
>cd applicaiton-name
>play ~run
Open http://localhost:9090 in your favourite
browser (if your favourite browser is IE - open
it in Chrome ;)
Generated dirs structure
app

→ Application sources

└ assets

→ Compiled asset sources (stylesheets and javascripts)

└ controllers

→ Application controllers

└ models

→ Application business layer

└ views

→ Templates

build.sbt

→ Application build script

conf

→ Configurations files and other non-compiled resources (on classpath)

└ application.conf
└ routes

→ Main configuration file
→ Routes definition

public

→ Public assets

└ stylesheets

→ CSS files

└ javascripts

→ Javascript files

└ images

→ Image files

project

→ sbt configuration files

└ build.properties
└ plugins.sbt
lib
logs

→ sbt plugins including the declaration for Play itself
→ Unmanaged libraries dependencies
→ Standard logs folder

└ application.log
target

→ Marker for sbt project

→ Default log file
→ Generated stuff (including generated sources out of scala views)

└ scala-2.10.0
test

→ source folder for unit or functional tests
Basic play console commands
Workflow commands:
>play compile
>play run
>play test
>play clean-all
>play debug
>play eclise #generates eclipse project to use with ScalaIde 3.0.2
auto triggering (as in SBT)
>play ~ compile|run|test
Application development
● Global Application Object
- can control life-time events in an app

● Controllers
- do hard work around HTTP requests

● Routing
- binds requested URLs with particular Controllers

● Predefined results
● Sessions and Flashes
● Async results
Global Application Object
import play.api.GlobalSettings
import play.api.mvc.RequestHeader
import play.api.mvc.Handler
import play.api.Logger
object Global extends GlobalSettings {
override def onRouteRequest(request:RequestHeader):Option
[Handler] = {
Logger.debug("on Request Routed" + request)
super.onRouteRequest(request)
}
}
In application.conf
application.global=app.Global
Controllers
import play.api.mvc.Controller
import play.api.mvc.Results._
import play.api.mvc.Action
object Tasks extends Controller {
def list = Action {
Ok("it works")
}
}
GET

/tasks

controllers.Tasks.list
Views
● Are in 90% in HTML + Scala-like expression
● Are compiled to Scala Objects
● View class is actually a … method body
We can create a reusable layout of a webapp:
views/templates/tasks.scala.html
and use it to form result content
views/tasks/list.scala.html
Models (DAOs and Entities)
We need a dependency for MySQL JDBC connector
in Build.scala we add
"mysql" % "mysql-connector-java" % "5.1.18",
in application.conf we add (to see SQL stmnts) :
db.default.logStatements=true
More at
http://www.playframework.com/documentation/2.1.x/ScalaDatabase
Models (DAOs and Entities)
import play.api.Play.current //imports current application
object into scope
import play.api.db._ //imports DB api (facade for JDBC)
//Retreiving connection
val ds = DB.getDataSource()
//lub
val connection = DB.getConnection()
//lub
DB.withConnection("default") { conn =>
// do whatever you need with the connection
}
… so let’s create an Entity and DAO and do some coding
… after coding - time to sum up
●
●
●
●
●
●
●
●

Native JSON and XML support
Powerful routing syntax
Web Services client (sync, async)
Build in translations management
Asynchronous HTTP programming
Less/CoffeScript support
ClosureCompiler/RequireJS support
many many more ;)
THE END
Lukasz Wójcik

Mais conteúdo relacionado

Destaque

Bcg Consultants Love Life
Bcg  Consultants Love LifeBcg  Consultants Love Life
Bcg Consultants Love Lifenitinagarwalin
 
Lab session #2: The Human Company
Lab session #2: The Human CompanyLab session #2: The Human Company
Lab session #2: The Human CompanyLuminary Labs
 
e-conomy SEA by Google and Temasek
e-conomy SEA by Google and Temaseke-conomy SEA by Google and Temasek
e-conomy SEA by Google and TemasekeconomySEA
 
Teaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakTeaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakShelly Sanchez Terrell
 
Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013
Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013
Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013Cain Ransbottyn
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?Maciej Lasyk
 
Great Talks Start with Great Proposals: An IA Summit Virtual Webinar
Great Talks Start with Great Proposals: An IA Summit Virtual WebinarGreat Talks Start with Great Proposals: An IA Summit Virtual Webinar
Great Talks Start with Great Proposals: An IA Summit Virtual WebinarRuss U
 
Designing a Culture of Design
Designing a Culture of DesignDesigning a Culture of Design
Designing a Culture of DesignChris Avore
 
Mobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitro
Mobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitroMobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitro
Mobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitroTorsten Schollmayer
 
Entrepreneurshit. The Truth About Building Starutps
Entrepreneurshit. The Truth About Building StarutpsEntrepreneurshit. The Truth About Building Starutps
Entrepreneurshit. The Truth About Building StarutpsMark Suster
 
Subscribed 2015: CEO's Keynote
Subscribed 2015: CEO's KeynoteSubscribed 2015: CEO's Keynote
Subscribed 2015: CEO's KeynoteZuora, Inc.
 

Destaque (14)

Docker.io
Docker.ioDocker.io
Docker.io
 
Bcg Consultants Love Life
Bcg  Consultants Love LifeBcg  Consultants Love Life
Bcg Consultants Love Life
 
Lab session #2: The Human Company
Lab session #2: The Human CompanyLab session #2: The Human Company
Lab session #2: The Human Company
 
e-conomy SEA by Google and Temasek
e-conomy SEA by Google and Temaseke-conomy SEA by Google and Temasek
e-conomy SEA by Google and Temasek
 
Teaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakTeaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & Textspeak
 
Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013
Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013
Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
Quantum computing
Quantum computingQuantum computing
Quantum computing
 
Great Talks Start with Great Proposals: An IA Summit Virtual Webinar
Great Talks Start with Great Proposals: An IA Summit Virtual WebinarGreat Talks Start with Great Proposals: An IA Summit Virtual Webinar
Great Talks Start with Great Proposals: An IA Summit Virtual Webinar
 
Designing a Culture of Design
Designing a Culture of DesignDesigning a Culture of Design
Designing a Culture of Design
 
Mobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitro
Mobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitroMobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitro
Mobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitro
 
Entrepreneurshit. The Truth About Building Starutps
Entrepreneurshit. The Truth About Building StarutpsEntrepreneurshit. The Truth About Building Starutps
Entrepreneurshit. The Truth About Building Starutps
 
Subscribed 2015: CEO's Keynote
Subscribed 2015: CEO's KeynoteSubscribed 2015: CEO's Keynote
Subscribed 2015: CEO's Keynote
 
The Hierarchy of Engagement
The Hierarchy of EngagementThe Hierarchy of Engagement
The Hierarchy of Engagement
 

Último

UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 

Último (20)

UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 

Quick Bootstrap to PlayFramework 2.1t

  • 1. Quick bootstrap into PlayFramework (2.1.x) Łukasz Wójcik
  • 2. First step ● Download PlayFramework from www. playframework.com/download ● Add corresponding path to PATH ● Check if it works calling >play help
  • 3. Creating and running an Application Navigate to your projects directory, and type >play new application-name >cd applicaiton-name >play ~run Open http://localhost:9090 in your favourite browser (if your favourite browser is IE - open it in Chrome ;)
  • 4. Generated dirs structure app → Application sources └ assets → Compiled asset sources (stylesheets and javascripts) └ controllers → Application controllers └ models → Application business layer └ views → Templates build.sbt → Application build script conf → Configurations files and other non-compiled resources (on classpath) └ application.conf └ routes → Main configuration file → Routes definition public → Public assets └ stylesheets → CSS files └ javascripts → Javascript files └ images → Image files project → sbt configuration files └ build.properties └ plugins.sbt lib logs → sbt plugins including the declaration for Play itself → Unmanaged libraries dependencies → Standard logs folder └ application.log target → Marker for sbt project → Default log file → Generated stuff (including generated sources out of scala views) └ scala-2.10.0 test → source folder for unit or functional tests
  • 5. Basic play console commands Workflow commands: >play compile >play run >play test >play clean-all >play debug >play eclise #generates eclipse project to use with ScalaIde 3.0.2 auto triggering (as in SBT) >play ~ compile|run|test
  • 6. Application development ● Global Application Object - can control life-time events in an app ● Controllers - do hard work around HTTP requests ● Routing - binds requested URLs with particular Controllers ● Predefined results ● Sessions and Flashes ● Async results
  • 7. Global Application Object import play.api.GlobalSettings import play.api.mvc.RequestHeader import play.api.mvc.Handler import play.api.Logger object Global extends GlobalSettings { override def onRouteRequest(request:RequestHeader):Option [Handler] = { Logger.debug("on Request Routed" + request) super.onRouteRequest(request) } } In application.conf application.global=app.Global
  • 8. Controllers import play.api.mvc.Controller import play.api.mvc.Results._ import play.api.mvc.Action object Tasks extends Controller { def list = Action { Ok("it works") } } GET /tasks controllers.Tasks.list
  • 9. Views ● Are in 90% in HTML + Scala-like expression ● Are compiled to Scala Objects ● View class is actually a … method body We can create a reusable layout of a webapp: views/templates/tasks.scala.html and use it to form result content views/tasks/list.scala.html
  • 10. Models (DAOs and Entities) We need a dependency for MySQL JDBC connector in Build.scala we add "mysql" % "mysql-connector-java" % "5.1.18", in application.conf we add (to see SQL stmnts) : db.default.logStatements=true More at http://www.playframework.com/documentation/2.1.x/ScalaDatabase
  • 11. Models (DAOs and Entities) import play.api.Play.current //imports current application object into scope import play.api.db._ //imports DB api (facade for JDBC) //Retreiving connection val ds = DB.getDataSource() //lub val connection = DB.getConnection() //lub DB.withConnection("default") { conn => // do whatever you need with the connection } … so let’s create an Entity and DAO and do some coding
  • 12. … after coding - time to sum up ● ● ● ● ● ● ● ● Native JSON and XML support Powerful routing syntax Web Services client (sync, async) Build in translations management Asynchronous HTTP programming Less/CoffeScript support ClosureCompiler/RequireJS support many many more ;)