SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Play! framework
                  Agile web development.


                Created by Guillaume Bort 2007




Sẩm Bảo Chung     Web development with Play!
Agenda
      Overview
      Main Concept
            Five cool things you can do with play
            Fix the bug and hit Reload
            Simple stateless MVC architecture
            Efficient template engine
            Test driven development
            Job
      Play enviroment
      Discuss




Sẩm Bảo Chung        Web development with Play!
Play Overview
      Pure   Java
      More    productive Java environment!
      Targets   Restful architectures
      No   compile, deploy, restart cycle - Fix the bug and hit
      reload!
      Clean    template system - using Groovy, Scala template
      Exact    errors (including line numbers, even for templates)
      Lots   of built-in features for fast development
      Starts   fast, runs fast
      Extensible    by modules


Sẩm Bảo Chung          Web development with Play
Main Concept

      Simple   stateless MVC architecture
      Five   cool things you can do with play
      Fix   the bug and hit Reload
      Efficient   template engine
      JPA

      Test   driven development
      Job




Sẩm Bảo Chung          Web development with Play!
Play architecture MVC
                            The Play framework is fully stateless and
                            only request/response-oriented
                            4.AnHTTP Request is received by the
                            framework.
                            6.TheRouter component tries to find the
                            most specific route able to accept this
                            request.
                            8.The corresponding action method is
                            then invoked.
                            10.The application code is executed.
                            11.If a complex view needs to be
                            generated, a template file is rendered.
                            13.The result of the action method (HTTP
                            Response code, Content) is then written
                            as an HTTP Response.




Sẩm Bảo Chung   Web development with Play!
Routes file
      A routes file help play controller routine
      the request

      GET / Ap p l i c a t i o n . i n d e x
      GET / u s e r /{ username } Ap p l i c a t i o n . showUser
      POST / u s e r                  Ap p l i c a t i o n . c r e a t
      eUs e r
      DELETE / u s e r /{ username }           Ap p l i c a t i o n . d e
      l e t eUs e r
      GET / p u b l i c       staticDir:public



Sẩm Bảo Chung         Web development with Play
Model
      A   simple user

      @Entity
      public class User extends Model{

           @Id
           public long id;

           @Required
           @Column(unique = true)
           public String username;

           @Required
           @Email
           public String email;
      }


Sẩm Bảo Chung        Web development with Play
Controller
      UserController
      public class Application extends Controller {
          public static void index() {
          List<User> users = User.findAll();
          render(users);
          }

          public static void showUser(String username) {
          User user = User.find("byUsername",
             username).first();
          notFoundIfNull(user);
          render(user);
      }


Sẩm Bảo Chung        Web development with Play
View
      List users
      (app/views/Application/index.html)
         #{ extends ’main .html ’ /}
         #{ set title :’Index ’ /}
         <ul >
         #{ list items :users , as:’user ’}
            <li >
            #{a @Application . showUser ( user .
                username )}
                ${ user . username }
            #{/ a}
            with email address ${ user . email }
            </li >
         #{/ list }
         </ul >

Sẩm Bảo Chung         Web development with Play
Five cool things of Play!
      Bind   an HTTP parameter to a Java method parameter




      Redirect   to an action by calling the corresponding Java
      method
             render(…) , renderText(…), renderXML(…),
      renderJSON(…), renderBinary(…), redirect(…)



Sẩm Bảo Chung          Web development with Play
Five cool things of Play!
      Don’t  Repeat Yourself when passing Java objects to
      templates
      Play will automatically start the JPA Entity Manager
      using Hibernate and magically synchronize it when code
      is reloaded.




Sẩm Bảo Chung      Web development with Play
Five cool things of Play!
      Straightforward   file upload management

      #{form @uploadPhoto(), enctype:'multipart/form-
      data'} <input type="text" name="title" /> <input
      type="file" id="photo" name="photo" /> <input
      type="submit" value="Send it..." /> #{/}

      public static void uploadPhoto(String title, File photo)
      { ...
      }




Sẩm Bảo Chung        Web development with Play
Fix the bug and hit
    Reload
      Whenever an error occurs, the framework makes its best
      effort to identify and show you the problem




Sẩm Bảo Chung      Web development with Play
Job
         Doing the right thing at the right time
          •   Scheduled jobs (housekeeping)
          •   Bootstrap jobs (initial data providing)
          •   Suspendable requests (rendering a PDF
              report without blocking the
          •   connection thread pool)
      /* @Every("1h") */
      @OnApplicationStart
      public class LoadDataJob extends Job {
          public void doJob() {
          /* .. do whatever you want */
          }
      }



Sẩm Bảo Chung        Web development with Play
Test driven development
      The integrated test runner makes it easy for you do test-
                                          driven development.




Sẩm Bảo Chung      Web development with Play
Getting start
      Using the play command
      When the framework is correctly installed, open a shell
      and execute play.
      $ play
      You should see the play default message.




Sẩm Bảo Chung       Web development with Play
Getting start
      Use the new command to create a new application.
      # play new myApp




Sẩm Bảo Chung      Web development with Play
Getting start
      You can start with command
      # play run myApp




Sẩm Bảo Chung      Web development with Play
Modules
      Some module on
      http://www.playframework.org/modules
      With:
      Scala
      Google App Engine
      PDF Generation
      SASS and SCSS
      Google Web Toolkit
      MongoDB
      Simple search
      Objectify
      To install locally these modules use the install command:
      play install gae-{version}
      To add this module as dependency of your application, add it
      to the dependencies.yml file:
      require: - play -> gae {version}.



Sẩm Bảo Chung        Web development with Play

Weitere ähnliche Inhalte

Was ist angesagt?

Play Framework: The Basics
Play Framework: The BasicsPlay Framework: The Basics
Play Framework: The Basics
Philip Langer
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_final
NAVER D2
 
Java Development EcoSystem
Java Development EcoSystemJava Development EcoSystem
Java Development EcoSystem
Alex Tumanoff
 

Was ist angesagt? (20)

Introduction to Play Framework
Introduction to Play FrameworkIntroduction to Play Framework
Introduction to Play Framework
 
Play Framework: The Basics
Play Framework: The BasicsPlay Framework: The Basics
Play Framework: The Basics
 
Migrating to Java 9 Modules
Migrating to Java 9 ModulesMigrating to Java 9 Modules
Migrating to Java 9 Modules
 
Getting Started with Java EE 7
Getting Started with Java EE 7Getting Started with Java EE 7
Getting Started with Java EE 7
 
An Introduction to Play 2 Framework
An Introduction to Play 2 FrameworkAn Introduction to Play 2 Framework
An Introduction to Play 2 Framework
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
 
JSF2
JSF2JSF2
JSF2
 
Migrating to java 9 modules
Migrating to java 9 modulesMigrating to java 9 modules
Migrating to java 9 modules
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_final
 
Step by step guide to create theme for liferay dxp 7
Step by step guide to create theme for liferay dxp 7Step by step guide to create theme for liferay dxp 7
Step by step guide to create theme for liferay dxp 7
 
[143]Inside fuse deview 2016
[143]Inside fuse   deview 2016[143]Inside fuse   deview 2016
[143]Inside fuse deview 2016
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Managed Beans: When, Why and How
Managed Beans: When, Why and HowManaged Beans: When, Why and How
Managed Beans: When, Why and How
 
Java Modularity: the Year After
Java Modularity: the Year AfterJava Modularity: the Year After
Java Modularity: the Year After
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0
 
Java Development EcoSystem
Java Development EcoSystemJava Development EcoSystem
Java Development EcoSystem
 
Scala and Play with Gradle
Scala and Play with GradleScala and Play with Gradle
Scala and Play with Gradle
 
Preparing your code for Java 9
Preparing your code for Java 9Preparing your code for Java 9
Preparing your code for Java 9
 

Andere mochten auch

Introduction into JavaFX
Introduction into JavaFXIntroduction into JavaFX
Introduction into JavaFX
Eugene Bogaart
 

Andere mochten auch (10)

Scalaz introduction for Java programmers
Scalaz introduction for Java programmersScalaz introduction for Java programmers
Scalaz introduction for Java programmers
 
Introduction into JavaFX
Introduction into JavaFXIntroduction into JavaFX
Introduction into JavaFX
 
Neo4J and Grails
Neo4J and GrailsNeo4J and Grails
Neo4J and Grails
 
Getting your Grails on
Getting your Grails onGetting your Grails on
Getting your Grails on
 
JavaFx
JavaFxJavaFx
JavaFx
 
Effective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjectsEffective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjects
 
JavaFX Uni Parthenope
JavaFX Uni ParthenopeJavaFX Uni Parthenope
JavaFX Uni Parthenope
 
Message Driven Architecture in Grails
Message Driven Architecture in GrailsMessage Driven Architecture in Grails
Message Driven Architecture in Grails
 
OpenJFX on Android and Devices
OpenJFX on Android and DevicesOpenJFX on Android and Devices
OpenJFX on Android and Devices
 
Building Java Desktop Apps with JavaFX 8 and Java EE 7
Building Java Desktop Apps with JavaFX 8 and Java EE 7Building Java Desktop Apps with JavaFX 8 and Java EE 7
Building Java Desktop Apps with JavaFX 8 and Java EE 7
 

Ähnlich wie Play framework

eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introduction
vstorm83
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 

Ähnlich wie Play framework (20)

eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introduction
 
Using HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in JavaUsing HttpWatch Plug-in with Selenium Automation in Java
Using HttpWatch Plug-in with Selenium Automation in Java
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundry
 
Android UI Testing with Appium
Android UI Testing with AppiumAndroid UI Testing with Appium
Android UI Testing with Appium
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh Gundecha
 
Selenium.pptx
Selenium.pptxSelenium.pptx
Selenium.pptx
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!
 
Electron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyElectron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easy
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
The Play Framework at LinkedIn
The Play Framework at LinkedInThe Play Framework at LinkedIn
The Play Framework at LinkedIn
 
The Play Framework at LinkedIn: productivity and performance at scale - Jim B...
The Play Framework at LinkedIn: productivity and performance at scale - Jim B...The Play Framework at LinkedIn: productivity and performance at scale - Jim B...
The Play Framework at LinkedIn: productivity and performance at scale - Jim B...
 
Designing the Call of Cthulhu app with Google App Engine
Designing the Call of Cthulhu app with Google App EngineDesigning the Call of Cthulhu app with Google App Engine
Designing the Call of Cthulhu app with Google App Engine
 
Dive into Play Framework
Dive into Play FrameworkDive into Play Framework
Dive into Play Framework
 
Akash rajguru project report sem v
Akash rajguru project report sem vAkash rajguru project report sem v
Akash rajguru project report sem v
 
Google App Engine for Java
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for Java
 
Selenium Automation in Java Using HttpWatch Plug-in
 Selenium Automation in Java Using HttpWatch Plug-in  Selenium Automation in Java Using HttpWatch Plug-in
Selenium Automation in Java Using HttpWatch Plug-in
 
Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
Play Framework on Google App Engine
Play Framework on Google App EnginePlay Framework on Google App Engine
Play Framework on Google App Engine
 

Kürzlich hochgeladen

Simple Conference Style Presentation by Slidesgo.pptx
Simple Conference Style Presentation by Slidesgo.pptxSimple Conference Style Presentation by Slidesgo.pptx
Simple Conference Style Presentation by Slidesgo.pptx
balqisyamutia
 
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
awasv46j
 
一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证
一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证
一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证
wpkuukw
 
Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...
nirzagarg
 
怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证
怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证
怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证
eeanqy
 
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
ehyxf
 
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
sriharipichandi
 
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
HyderabadDolls
 
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
instagramfab782445
 

Kürzlich hochgeladen (20)

Q4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentationQ4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentation
 
Simple Conference Style Presentation by Slidesgo.pptx
Simple Conference Style Presentation by Slidesgo.pptxSimple Conference Style Presentation by Slidesgo.pptx
Simple Conference Style Presentation by Slidesgo.pptx
 
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
 
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
 
The hottest UI and UX Design Trends 2024
The hottest UI and UX Design Trends 2024The hottest UI and UX Design Trends 2024
The hottest UI and UX Design Trends 2024
 
UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...
UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...
UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...
 
Eye-Catching Web Design Crafting User Interfaces .docx
Eye-Catching Web Design Crafting User Interfaces .docxEye-Catching Web Design Crafting User Interfaces .docx
Eye-Catching Web Design Crafting User Interfaces .docx
 
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best ServiceHigh Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
 
一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证
一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证
一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证
 
Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...
Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...
Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...
 
Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...
 
怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证
怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证
怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证
 
Call Girls Jalaun Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Jalaun Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Jalaun Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Jalaun Just Call 8617370543 Top Class Call Girl Service Available
 
Raebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for Friendship
Raebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for FriendshipRaebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for Friendship
Raebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for Friendship
 
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
 
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
 
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
 
BLOCK CHAIN PROJECT block chain project
BLOCK CHAIN  PROJECT block chain projectBLOCK CHAIN  PROJECT block chain project
BLOCK CHAIN PROJECT block chain project
 
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
 
Essential UI/UX Design Principles: A Comprehensive Guide
Essential UI/UX Design Principles: A Comprehensive GuideEssential UI/UX Design Principles: A Comprehensive Guide
Essential UI/UX Design Principles: A Comprehensive Guide
 

Play framework

  • 1. Play! framework Agile web development. Created by Guillaume Bort 2007 Sẩm Bảo Chung Web development with Play!
  • 2. Agenda Overview Main Concept  Five cool things you can do with play  Fix the bug and hit Reload  Simple stateless MVC architecture  Efficient template engine  Test driven development  Job Play enviroment Discuss Sẩm Bảo Chung Web development with Play!
  • 3. Play Overview Pure Java More productive Java environment! Targets Restful architectures No compile, deploy, restart cycle - Fix the bug and hit reload! Clean template system - using Groovy, Scala template Exact errors (including line numbers, even for templates) Lots of built-in features for fast development Starts fast, runs fast Extensible by modules Sẩm Bảo Chung Web development with Play
  • 4. Main Concept Simple stateless MVC architecture Five cool things you can do with play Fix the bug and hit Reload Efficient template engine JPA Test driven development Job Sẩm Bảo Chung Web development with Play!
  • 5. Play architecture MVC The Play framework is fully stateless and only request/response-oriented 4.AnHTTP Request is received by the framework. 6.TheRouter component tries to find the most specific route able to accept this request. 8.The corresponding action method is then invoked. 10.The application code is executed. 11.If a complex view needs to be generated, a template file is rendered. 13.The result of the action method (HTTP Response code, Content) is then written as an HTTP Response. Sẩm Bảo Chung Web development with Play!
  • 6. Routes file A routes file help play controller routine the request GET / Ap p l i c a t i o n . i n d e x GET / u s e r /{ username } Ap p l i c a t i o n . showUser POST / u s e r Ap p l i c a t i o n . c r e a t eUs e r DELETE / u s e r /{ username } Ap p l i c a t i o n . d e l e t eUs e r GET / p u b l i c staticDir:public Sẩm Bảo Chung Web development with Play
  • 7. Model A simple user @Entity public class User extends Model{ @Id public long id; @Required @Column(unique = true) public String username; @Required @Email public String email; } Sẩm Bảo Chung Web development with Play
  • 8. Controller UserController public class Application extends Controller { public static void index() { List<User> users = User.findAll(); render(users); } public static void showUser(String username) { User user = User.find("byUsername", username).first(); notFoundIfNull(user); render(user); } Sẩm Bảo Chung Web development with Play
  • 9. View List users (app/views/Application/index.html) #{ extends ’main .html ’ /} #{ set title :’Index ’ /} <ul > #{ list items :users , as:’user ’} <li > #{a @Application . showUser ( user . username )} ${ user . username } #{/ a} with email address ${ user . email } </li > #{/ list } </ul > Sẩm Bảo Chung Web development with Play
  • 10. Five cool things of Play! Bind an HTTP parameter to a Java method parameter Redirect to an action by calling the corresponding Java method render(…) , renderText(…), renderXML(…), renderJSON(…), renderBinary(…), redirect(…) Sẩm Bảo Chung Web development with Play
  • 11. Five cool things of Play! Don’t Repeat Yourself when passing Java objects to templates Play will automatically start the JPA Entity Manager using Hibernate and magically synchronize it when code is reloaded. Sẩm Bảo Chung Web development with Play
  • 12. Five cool things of Play! Straightforward file upload management #{form @uploadPhoto(), enctype:'multipart/form- data'} <input type="text" name="title" /> <input type="file" id="photo" name="photo" /> <input type="submit" value="Send it..." /> #{/} public static void uploadPhoto(String title, File photo) { ... } Sẩm Bảo Chung Web development with Play
  • 13. Fix the bug and hit Reload Whenever an error occurs, the framework makes its best effort to identify and show you the problem Sẩm Bảo Chung Web development with Play
  • 14. Job  Doing the right thing at the right time • Scheduled jobs (housekeeping) • Bootstrap jobs (initial data providing) • Suspendable requests (rendering a PDF report without blocking the • connection thread pool) /* @Every("1h") */ @OnApplicationStart public class LoadDataJob extends Job { public void doJob() { /* .. do whatever you want */ } } Sẩm Bảo Chung Web development with Play
  • 15. Test driven development The integrated test runner makes it easy for you do test- driven development. Sẩm Bảo Chung Web development with Play
  • 16. Getting start Using the play command When the framework is correctly installed, open a shell and execute play. $ play You should see the play default message. Sẩm Bảo Chung Web development with Play
  • 17. Getting start Use the new command to create a new application. # play new myApp Sẩm Bảo Chung Web development with Play
  • 18. Getting start You can start with command # play run myApp Sẩm Bảo Chung Web development with Play
  • 19. Modules Some module on http://www.playframework.org/modules With: Scala Google App Engine PDF Generation SASS and SCSS Google Web Toolkit MongoDB Simple search Objectify To install locally these modules use the install command: play install gae-{version} To add this module as dependency of your application, add it to the dependencies.yml file: require: - play -> gae {version}. Sẩm Bảo Chung Web development with Play