SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Andere mochten auch

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.
 

Andere mochten auch (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
 

Kürzlich hochgeladen

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Kürzlich hochgeladen (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

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 ;)