SlideShare ist ein Scribd-Unternehmen logo
1 von 73
Downloaden Sie, um offline zu lesen
NFJS Software Symposium Series 2009



 Spring 2.5 MVC



Ken Sipe
Technology Director, Perficient (PRFT)
NFJS Software Symposium Series 2009

            3.0
 Spring 2.5 MVC



Ken Sipe
Technology Director, Perficient (PRFT)
Speaker Qualifications                                Spring 3.0 MVC




    SOA/Enterprise Architect


    Developer (Java, C++, C#, Objective-C)

    Instructor (VisiBroker, RUP, OOAD)


    Speaker (NFJS, JavaOne, JAX-India)

    Involved in Java since 1996


    Author (Pro Spring 3.0)





                                     kensipe@gmail.com
                                     kensipe.blogspot.com
                                     http://del.icio.us/kensipe
                                     twitter: kensipe
Agenda                            Spring 3.0 MVC




    Agenda

      Spring 3.0 - ADD
    
     Spring MVC
     From Controller to @Controller
            Controller Mapping
        

            URL Mapping
        

            Request Parameters
        

            Model Attributes
        

      Spring Forms
    
     Summary
Spring 3.0 MVC




Spring 3.0 - ADD
Annotated Driven Development
Introduction to IoC                                                          Spring 3.0 MVC




       AccountService              AccountDAO
      Attribute                    Attribute
      Attribute                                             DataSource
                                   Attribute
      Operation                                            Attribute
                                   Operation
                        <<uses>>
      Operation                                            Attribute
                                   Operation    <<uses>>




                                                                         5
Introduction to IoC                                                          Spring 3.0 MVC




       AccountService              AccountDAO
      Attribute                    Attribute
      Attribute                                             DataSource
                                   Attribute
      Operation                                            Attribute
                                   Operation
                        <<uses>>
      Operation                                            Attribute
                                   Operation    <<uses>>




                service dependency on datasource




                                                                         5
Introduction to IoC                                                           Spring 3.0 MVC




       AccountService              AccountDAO
      Attribute                    Attribute
      Attribute                                              DataSource
                                   Attribute
      Operation                                             Attribute
                                   Operation
                        <<uses>>
      Operation                                             Attribute
                                   Operation     <<uses>>

                                          <creates>

                                    DAOFactory
                                   Attribute
                                   Attribute
                                   Operation
                                   Operation


                        dependency simply moves




                                                                          5
Spring IoC                                                                          Spring 3.0 MVC




           AccountService                 AccountDAO
          Attribute                       Attribute
          Attribute                       Attribute                  DataSource
          Operation                       Operation                 Attribute
                            <<uses>>
          Operation                       Operation                 Attribute
                                                         <<uses>>

                                                  <creates>


                                        ApplicationContext
                                       Attribute
                                       Attribute
                                       Operation
                                       Operation




Client:




                                                                                  6
Spring 3.0 MVC




XML Configuration




                    7
Types of Injections                                      Spring 3.0 MVC




    There are 3 types of dependency

    injections in the world
     Constructor
           values are injected through the constructor at
       

           object construction
     Setter
           object is created, then values are set through each
       

           property setter
     Field
           object is created, then the values are (usually)
       

           reflectively set on the field (by passing the setter)


                                                          8
Spring 3.0 MVC




Spring Annotations
Spring 3.0 MVC




    @Component **

      Indicates that a class is a component
    
     Class is a candidate for auto-detection
     Custom component extensions

    @Controller

        Specialized Component
    

      Typically used with RequestMapping annotation
    
     Discussed in section on web mvc

    @Repository

        Now an extension of @Component
    

    @Service

        Intended to be a business service facade
    
Spring 3.0 MVC




    @Autowired

      Marks a constructor, field, setter or config method for injection.
    
     Fields are injected
         After construction
        @Autowired(required=false)
    

    @Qualifier

      Qualifies a bean for autowiring
    
     May be customized
    @Required

        Marks a method as being injection required
    
Types of Injections    Spring 3.0 MVC




    Constructor





    Setter





    Field





                           12
New Injection Type    Spring 3.0 MVC




    configuration

    method



    with any

    number of
    arguments




                          13
Spring 3.0 MVC




Spring MVC
Spring Web                                   Spring 3.0 MVC




    Spring Web MVC

     foundation    for all spring web modules
    Spring JavaScript

     ajax   support
    Spring Web Flow

     framework     for stateful interactions
    Spring Faces

     JSF    support
    Spring Portlet

     Portlet   jsr-168 and jsr-286 support
                                                 15
MVC Overview                                    Spring 3.0 MVC




    MVC = Model - View - Controller

     separates:
         business
       

        navigation

        presentation logic

     Improves      testability of logic and navigation




                                                   16
MVC on the Web                       Spring 3.0 MVC




    Model

     data   container
         displayed by the view
       

        manipulated by the controller

     commonly      a simple map
    View

     typically   jsp or xml
    Controller

     controlling   logic
         conjuror of model
       

        navigation

        validation                      17
Spring 3.0 MVC




request                   request

          Dispatcher
                                       Controller
            Servlet

                          navigation
                                                    data access


                 render


                                                        DB
                           access

           view jsp
                                        Model




                                                                  18
Spring MVC Taxonomy                               Spring 3.0 MVC




    DispatcherServlet

     Spring provided front controller
     Controls request routing
    Controllers

                                 TIP:
     User created POJO          1. Delegate to service beans
                                 for business logic
     Standard Spring beans      2. handle only navigation

    View

     Responsible    for rendering a response



                                                     19
Core MVC Components                              Spring 3.0 MVC




    ModelAndView

     storesmodel data
     associates a view to the request
           can be a view implementation or a logical name
       

    ViewResolver

     Used to map logical view names to view
      implementations
    HandlerMapping

     Strategy  interface
     Used by DispatcherServlet to map requests to
      controllers
                                                    20
Spring Views                           Spring 3.0 MVC




    Extensive Support

     JSP,Velocity, FreeMarker, JasperReporters
     PDF, Excel
    Views are mapped by ViewResolvers





                                           21
Spring View    Spring 3.0 MVC




              22
Spring Controller Hierarchy    Spring 3.0 MVC




                              23
Spring MVC Old School    Spring 3.0 MVC




                        24
Spring MVC Old School    Spring 3.0 MVC




                        25
Spring MVC Old School - Working with Requests    Spring 3.0 MVC




                                                26
Spring 3.0 MVC




DEMO: Spring MVC Old School
Spring 3.0 MVC




From Controller to @Controller
           Spring 3 @MVC
Spring MVC Annotations                                        Spring 3.0 MVC




    @Controller

      Stereotype used to “Controller” of MVC
    
     Scanned for RequestMappings

    @RequestMapping

      Annotates a handler method for a request
    
     Very flexible

    @RequestParam

        Annotates that a method parameter should be bound to a web request
    
        parameter
    SessionAttributes

        Marks session attributes that a handler uses
    
New Controller Issues           Spring 3.0 MVC




  Doesn’t implement an Interface

 Multiple request mappings
 High degree of flexibility




                                   30
Advantages of Controller Interfaces    Spring 3.0 MVC




                                      31
Advantages of Controller Interfaces               Spring 3.0 MVC




                                      It looks like your trying
                                      to build a controller




                                                31
Advantages of Controller Interfaces    Spring 3.0 MVC




                                      31
A World Without Rules               Spring 3.0 MVC




                          Return Type?
                        
                         Parameters?




                                   32
Spring MVC Parameters and Return Types                   Spring 3.0 MVC




    Parameters can be

        Request / response / session
    
        WebRequest
    
        InputStream
    
        OutputStream
    
        @RequestParam
    
        +++
    

    Return types

        ModelAndView Object
    
        Model Object
    
        Map for exposing model
    
        View Object
    
        String which is a view name
    
        Void… if method wrote the response content directly
    
Spring MVC Controller Evolution                                  Spring 3.0 MVC




   mixed model: standard looking old school controller without
   an interface.

                                                             34
Spring MVC Controller Evolution                            Spring 3.0 MVC




   refactored method: inject the model, return the view


                                                          35
Spring MVC Controller Evolution                                Spring 3.0 MVC




   another refactor: just return the model data, view is assumed through
   convention.

                                                             36
Spring MVC By Convention                     Spring 3.0 MVC




                                  Conventions:
                                  hotel = HotelController
                GET /hotel/list   list = method

View selected
from request
path



Added to
Model




                                                37
Multi-Action Convention    Spring 3.0 MVC




     /hotel/index


     /hotel/show


     /hotel/list




                          38
Parameters           Spring 3.0 MVC




/hotel/show?id=42




                    39
Spring 3.0 MVC




Spring MVC Configurations
URL Autonomy                                               Spring 3.0 MVC




http://<host>:<port>/petclinic/main/owner/show

                Web Application/Servlet/Controller/method




                                                        41
DispatcherServlet    Spring 3.0 MVC




                    42
DispatcherServlet    Spring 3.0 MVC




                    42
Handler Mappings                     Spring 3.0 MVC




    DefaultAnnotationHandlerMapping

     annotation   based - @Controller
    SimpleUrlHandlerMapping

     configuration  based
     still works with annotations
    ControllerClassNameHandlerMapping



    UrlFileNameViewController

     views   without a controller

                                         43
Mapping by Request Mapping    Spring 3.0 MVC




                             44
Mapping by Controller    Spring 3.0 MVC




                        45
Mapping by Convention    Spring 3.0 MVC




                        46
Spring MVC Tips                Spring 3.0 MVC




  Favor @Controller

 Convention over configuration
 Group controller logic




                                  47
Controller Class Name Conventions                  Spring 3.0 MVC




                   /petclinic/main/owner/show

                          org...petclinic.Owner




                                                  48
Controller Class Name Conventions - Base Package        Spring 3.0 MVC




                   /petclinic/main/patient/owner/show

                               org...petclinic.Owner




                                                       49
Controller Class Name Conventions - Base Package        Spring 3.0 MVC




                   /petclinic/main/patient/owner/show
                                     prefix

                               org...petclinic.Owner




                                                       50
@RequestMapping                                Spring 3.0 MVC




    Order of method selection:

         First by request method (GET, POST, PUT,
       

         DELETE)
        Second by parameter presence/absense, or

         parameter value
        third by method name

        fourth by URL




                                                51
Method-Relative Request Mapping                     Spring 3.0 MVC




                       /owner, /owner/*


                                              GET /owner/form


                                             POST /owner/form

                                              GET /owner/find



                                          GET /owner/find?submit=




                                                   52
View Name Conventions                Spring 3.0 MVC




Show owner:

      GET /owner/show

Add or edit owner:
      GET /owner/form
      GET /owner/form?id=
      POST /owner/form

Search owner:
     GET /owner/find
     GET      /owner/find?submit=




                                    53
Views without Controllers                    Spring 3.0 MVC




      Some views don’t review a controller
  

           /index.htm -> “index”
       
@RequestParam                                          Spring 3.0 MVC




type conversion




optional request parameter




                              TIP: for optional parameters use objects




GET    /owner/show?submit=2



                                                           55
@PathVariable - RESTFUL    Spring 3.0 MVC




GET   /owner/show/2




                                 56
Add Model Attributes              Spring 3.0 MVC




  Automatically created on every request

 Implicit Model




                                     57
Adding a Single Model Attribute                              Spring 3.0 MVC




Implicit Model




@ModelAttribute - customize the name




                                 TIP: If you need more than one model
                                 attribute, take model as a input argument




                                                                58
More Crazy Stuff       Spring 3.0 MVC




    Annotation Access to:

     Headers
     Cookies




                            59
Working with Session                        Spring 3.0 MVC




                       Session Attribute for “pet”




                       “pet” will be added to session



                       “pet” will be removed from
                       session




                                          60
Spring 3.0 MVC




Spring Forms
Model Attributes as Command Objects    Spring 3.0 MVC




Bind command object to form




Bind request to command object




                                      62
Submitting Forms    Spring 3.0 MVC




                   63
Model Validation         Spring 3.0 MVC




  Hibernate Validator

 JSR-303 Bean Validation




                            64
Validation Checks in Controller    Spring 3.0 MVC




                                  65
Spring 3.0 MVC




DEMO: Spring 3.0 MVC
Summary                                                       Spring 3.0 MVC




    Closing and Q&A

        References
    
             Spring Framework: http://www.springsource.com/download/
         
             community?project=Spring%20Framework
             Spring Docs: http://www.springsource.org/documentation
         

             Session Source Code: http://groups.google.com/group/codemash
         

      Please fill out the session evaluation
    
     Ken Sipe – kensipe@gmail.com

Weitere ähnliche Inhalte

Was ist angesagt?

JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6Bert Ertman
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depthVinay Kumar
 
Spring Framework
Spring FrameworkSpring Framework
Spring Frameworknomykk
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkRaveendra R
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Spring framework-tutorial
Spring framework-tutorialSpring framework-tutorial
Spring framework-tutorialvinayiqbusiness
 
Spring MVC
Spring MVCSpring MVC
Spring MVCyuvalb
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Hitesh-Java
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlArjun Thakur
 
Introduction to Ibatis by Rohit
Introduction to Ibatis by RohitIntroduction to Ibatis by Rohit
Introduction to Ibatis by RohitRohit Prabhakar
 
Spring framework
Spring frameworkSpring framework
Spring frameworkAircon Chen
 
Java EE vs Spring Framework
Java  EE vs Spring Framework Java  EE vs Spring Framework
Java EE vs Spring Framework Rohit Kelapure
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
The 2014 Decision Makers Guide to Java Web Frameworks
The 2014 Decision Makers Guide to Java Web FrameworksThe 2014 Decision Makers Guide to Java Web Frameworks
The 2014 Decision Makers Guide to Java Web FrameworksKunal Ashar
 

Was ist angesagt? (19)

JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring framework-tutorial
Spring framework-tutorialSpring framework-tutorial
Spring framework-tutorial
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
 
Introduction to Ibatis by Rohit
Introduction to Ibatis by RohitIntroduction to Ibatis by Rohit
Introduction to Ibatis by Rohit
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Java spring ppt
Java spring pptJava spring ppt
Java spring ppt
 
Java EE vs Spring Framework
Java  EE vs Spring Framework Java  EE vs Spring Framework
Java EE vs Spring Framework
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring Framework Training Course
Spring Framework Training Course Spring Framework Training Course
Spring Framework Training Course
 
The 2014 Decision Makers Guide to Java Web Frameworks
The 2014 Decision Makers Guide to Java Web FrameworksThe 2014 Decision Makers Guide to Java Web Frameworks
The 2014 Decision Makers Guide to Java Web Frameworks
 

Ähnlich wie Spring 3 MVC CodeMash 2009

ASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web developmentASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web developmentVolodymyr Voytyshyn
 
NIG 系統開發指引
NIG 系統開發指引NIG 系統開發指引
NIG 系統開發指引Guo Albert
 
Spring MVC introduction HVA
Spring MVC introduction HVASpring MVC introduction HVA
Spring MVC introduction HVAPeter Maas
 
MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011MongoDB
 
Gnizr Architecture (for developers)
Gnizr Architecture (for developers)Gnizr Architecture (for developers)
Gnizr Architecture (for developers)hchen1
 
RESTful apps and services with ASP.NET MVC
RESTful apps and services with ASP.NET MVCRESTful apps and services with ASP.NET MVC
RESTful apps and services with ASP.NET MVCbnoyle
 
Esri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc FinalEsri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc Finalguestcd4688
 
Unit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxUnit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxAbhijayKulshrestha1
 
MongoDB for Java Developers with Spring Data
MongoDB for Java Developers with Spring DataMongoDB for Java Developers with Spring Data
MongoDB for Java Developers with Spring DataChris Richardson
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)Carles Farré
 
Structure mapping your way to better software
Structure mapping your way to better softwareStructure mapping your way to better software
Structure mapping your way to better softwarematthoneycutt
 
SaaS transformation with OCE - uEngineCloud
SaaS transformation with OCE - uEngineCloudSaaS transformation with OCE - uEngineCloud
SaaS transformation with OCE - uEngineClouduEngine Solutions
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)Carles Farré
 
Spring training
Spring trainingSpring training
Spring trainingTechFerry
 

Ähnlich wie Spring 3 MVC CodeMash 2009 (20)

Introducing spring
Introducing springIntroducing spring
Introducing spring
 
ASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web developmentASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web development
 
NIG 系統開發指引
NIG 系統開發指引NIG 系統開發指引
NIG 系統開發指引
 
Spring MVC introduction HVA
Spring MVC introduction HVASpring MVC introduction HVA
Spring MVC introduction HVA
 
MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011
 
ASP.NET MVC 3
ASP.NET MVC 3ASP.NET MVC 3
ASP.NET MVC 3
 
Gnizr Architecture (for developers)
Gnizr Architecture (for developers)Gnizr Architecture (for developers)
Gnizr Architecture (for developers)
 
RESTful apps and services with ASP.NET MVC
RESTful apps and services with ASP.NET MVCRESTful apps and services with ASP.NET MVC
RESTful apps and services with ASP.NET MVC
 
Esri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc FinalEsri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc Final
 
Mvc3 crash
Mvc3 crashMvc3 crash
Mvc3 crash
 
Unit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxUnit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptx
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
MongoDB for Java Developers with Spring Data
MongoDB for Java Developers with Spring DataMongoDB for Java Developers with Spring Data
MongoDB for Java Developers with Spring Data
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
 
Structure mapping your way to better software
Structure mapping your way to better softwareStructure mapping your way to better software
Structure mapping your way to better software
 
SaaS transformation with OCE - uEngineCloud
SaaS transformation with OCE - uEngineCloudSaaS transformation with OCE - uEngineCloud
SaaS transformation with OCE - uEngineCloud
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)
 
JavaCro'15 - Web UI best practice integration with Java EE 7 - Peter Lehto
JavaCro'15 - Web UI best practice integration with Java EE 7 - Peter LehtoJavaCro'15 - Web UI best practice integration with Java EE 7 - Peter Lehto
JavaCro'15 - Web UI best practice integration with Java EE 7 - Peter Lehto
 
Spring training
Spring trainingSpring training
Spring training
 
Unit Testing 101
Unit Testing 101Unit Testing 101
Unit Testing 101
 

Kürzlich hochgeladen

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Kürzlich hochgeladen (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

Spring 3 MVC CodeMash 2009

  • 1. NFJS Software Symposium Series 2009 Spring 2.5 MVC Ken Sipe Technology Director, Perficient (PRFT)
  • 2. NFJS Software Symposium Series 2009 3.0 Spring 2.5 MVC Ken Sipe Technology Director, Perficient (PRFT)
  • 3. Speaker Qualifications Spring 3.0 MVC SOA/Enterprise Architect  Developer (Java, C++, C#, Objective-C)  Instructor (VisiBroker, RUP, OOAD)  Speaker (NFJS, JavaOne, JAX-India)  Involved in Java since 1996  Author (Pro Spring 3.0)  kensipe@gmail.com kensipe.blogspot.com http://del.icio.us/kensipe twitter: kensipe
  • 4. Agenda Spring 3.0 MVC Agenda  Spring 3.0 - ADD   Spring MVC  From Controller to @Controller Controller Mapping  URL Mapping  Request Parameters  Model Attributes  Spring Forms   Summary
  • 5. Spring 3.0 MVC Spring 3.0 - ADD Annotated Driven Development
  • 6. Introduction to IoC Spring 3.0 MVC AccountService AccountDAO Attribute Attribute Attribute DataSource Attribute Operation Attribute Operation <<uses>> Operation Attribute Operation <<uses>> 5
  • 7. Introduction to IoC Spring 3.0 MVC AccountService AccountDAO Attribute Attribute Attribute DataSource Attribute Operation Attribute Operation <<uses>> Operation Attribute Operation <<uses>> service dependency on datasource 5
  • 8. Introduction to IoC Spring 3.0 MVC AccountService AccountDAO Attribute Attribute Attribute DataSource Attribute Operation Attribute Operation <<uses>> Operation Attribute Operation <<uses>> <creates> DAOFactory Attribute Attribute Operation Operation dependency simply moves 5
  • 9. Spring IoC Spring 3.0 MVC AccountService AccountDAO Attribute Attribute Attribute Attribute DataSource Operation Operation Attribute <<uses>> Operation Operation Attribute <<uses>> <creates> ApplicationContext Attribute Attribute Operation Operation Client: 6
  • 10. Spring 3.0 MVC XML Configuration 7
  • 11. Types of Injections Spring 3.0 MVC There are 3 types of dependency  injections in the world  Constructor values are injected through the constructor at  object construction  Setter object is created, then values are set through each  property setter  Field object is created, then the values are (usually)  reflectively set on the field (by passing the setter) 8
  • 12. Spring 3.0 MVC Spring Annotations
  • 13. Spring 3.0 MVC @Component **  Indicates that a class is a component   Class is a candidate for auto-detection  Custom component extensions @Controller  Specialized Component  Typically used with RequestMapping annotation   Discussed in section on web mvc @Repository  Now an extension of @Component  @Service  Intended to be a business service facade 
  • 14. Spring 3.0 MVC @Autowired  Marks a constructor, field, setter or config method for injection.   Fields are injected  After construction @Autowired(required=false)  @Qualifier  Qualifies a bean for autowiring   May be customized @Required  Marks a method as being injection required 
  • 15. Types of Injections Spring 3.0 MVC Constructor  Setter  Field  12
  • 16. New Injection Type Spring 3.0 MVC configuration  method with any  number of arguments 13
  • 18. Spring Web Spring 3.0 MVC Spring Web MVC   foundation for all spring web modules Spring JavaScript   ajax support Spring Web Flow   framework for stateful interactions Spring Faces   JSF support Spring Portlet   Portlet jsr-168 and jsr-286 support 15
  • 19. MVC Overview Spring 3.0 MVC MVC = Model - View - Controller   separates: business   navigation  presentation logic  Improves testability of logic and navigation 16
  • 20. MVC on the Web Spring 3.0 MVC Model   data container displayed by the view   manipulated by the controller  commonly a simple map View   typically jsp or xml Controller   controlling logic conjuror of model   navigation  validation 17
  • 21. Spring 3.0 MVC request request Dispatcher Controller Servlet navigation data access render DB access view jsp Model 18
  • 22. Spring MVC Taxonomy Spring 3.0 MVC DispatcherServlet   Spring provided front controller  Controls request routing Controllers  TIP:  User created POJO 1. Delegate to service beans for business logic  Standard Spring beans 2. handle only navigation View   Responsible for rendering a response 19
  • 23. Core MVC Components Spring 3.0 MVC ModelAndView   storesmodel data  associates a view to the request can be a view implementation or a logical name  ViewResolver   Used to map logical view names to view implementations HandlerMapping   Strategy interface  Used by DispatcherServlet to map requests to controllers 20
  • 24. Spring Views Spring 3.0 MVC Extensive Support   JSP,Velocity, FreeMarker, JasperReporters  PDF, Excel Views are mapped by ViewResolvers  21
  • 25. Spring View Spring 3.0 MVC 22
  • 26. Spring Controller Hierarchy Spring 3.0 MVC 23
  • 27. Spring MVC Old School Spring 3.0 MVC 24
  • 28. Spring MVC Old School Spring 3.0 MVC 25
  • 29. Spring MVC Old School - Working with Requests Spring 3.0 MVC 26
  • 30. Spring 3.0 MVC DEMO: Spring MVC Old School
  • 31. Spring 3.0 MVC From Controller to @Controller Spring 3 @MVC
  • 32. Spring MVC Annotations Spring 3.0 MVC @Controller  Stereotype used to “Controller” of MVC   Scanned for RequestMappings @RequestMapping  Annotates a handler method for a request   Very flexible @RequestParam  Annotates that a method parameter should be bound to a web request  parameter SessionAttributes  Marks session attributes that a handler uses 
  • 33. New Controller Issues Spring 3.0 MVC Doesn’t implement an Interface   Multiple request mappings  High degree of flexibility 30
  • 34. Advantages of Controller Interfaces Spring 3.0 MVC 31
  • 35. Advantages of Controller Interfaces Spring 3.0 MVC It looks like your trying to build a controller 31
  • 36. Advantages of Controller Interfaces Spring 3.0 MVC 31
  • 37. A World Without Rules Spring 3.0 MVC Return Type?   Parameters? 32
  • 38. Spring MVC Parameters and Return Types Spring 3.0 MVC Parameters can be  Request / response / session  WebRequest  InputStream  OutputStream  @RequestParam  +++  Return types  ModelAndView Object  Model Object  Map for exposing model  View Object  String which is a view name  Void… if method wrote the response content directly 
  • 39. Spring MVC Controller Evolution Spring 3.0 MVC mixed model: standard looking old school controller without an interface. 34
  • 40. Spring MVC Controller Evolution Spring 3.0 MVC refactored method: inject the model, return the view 35
  • 41. Spring MVC Controller Evolution Spring 3.0 MVC another refactor: just return the model data, view is assumed through convention. 36
  • 42. Spring MVC By Convention Spring 3.0 MVC Conventions: hotel = HotelController GET /hotel/list list = method View selected from request path Added to Model 37
  • 43. Multi-Action Convention Spring 3.0 MVC /hotel/index /hotel/show /hotel/list 38
  • 44. Parameters Spring 3.0 MVC /hotel/show?id=42 39
  • 45. Spring 3.0 MVC Spring MVC Configurations
  • 46. URL Autonomy Spring 3.0 MVC http://<host>:<port>/petclinic/main/owner/show Web Application/Servlet/Controller/method 41
  • 47. DispatcherServlet Spring 3.0 MVC 42
  • 48. DispatcherServlet Spring 3.0 MVC 42
  • 49. Handler Mappings Spring 3.0 MVC DefaultAnnotationHandlerMapping   annotation based - @Controller SimpleUrlHandlerMapping   configuration based  still works with annotations ControllerClassNameHandlerMapping  UrlFileNameViewController   views without a controller 43
  • 50. Mapping by Request Mapping Spring 3.0 MVC 44
  • 51. Mapping by Controller Spring 3.0 MVC 45
  • 52. Mapping by Convention Spring 3.0 MVC 46
  • 53. Spring MVC Tips Spring 3.0 MVC Favor @Controller   Convention over configuration  Group controller logic 47
  • 54. Controller Class Name Conventions Spring 3.0 MVC /petclinic/main/owner/show org...petclinic.Owner 48
  • 55. Controller Class Name Conventions - Base Package Spring 3.0 MVC /petclinic/main/patient/owner/show org...petclinic.Owner 49
  • 56. Controller Class Name Conventions - Base Package Spring 3.0 MVC /petclinic/main/patient/owner/show prefix org...petclinic.Owner 50
  • 57. @RequestMapping Spring 3.0 MVC Order of method selection:  First by request method (GET, POST, PUT,  DELETE)  Second by parameter presence/absense, or parameter value  third by method name  fourth by URL 51
  • 58. Method-Relative Request Mapping Spring 3.0 MVC /owner, /owner/* GET /owner/form POST /owner/form GET /owner/find GET /owner/find?submit= 52
  • 59. View Name Conventions Spring 3.0 MVC Show owner: GET /owner/show Add or edit owner: GET /owner/form GET /owner/form?id= POST /owner/form Search owner: GET /owner/find GET /owner/find?submit= 53
  • 60. Views without Controllers Spring 3.0 MVC Some views don’t review a controller  /index.htm -> “index” 
  • 61. @RequestParam Spring 3.0 MVC type conversion optional request parameter TIP: for optional parameters use objects GET /owner/show?submit=2 55
  • 62. @PathVariable - RESTFUL Spring 3.0 MVC GET /owner/show/2 56
  • 63. Add Model Attributes Spring 3.0 MVC Automatically created on every request   Implicit Model 57
  • 64. Adding a Single Model Attribute Spring 3.0 MVC Implicit Model @ModelAttribute - customize the name TIP: If you need more than one model attribute, take model as a input argument 58
  • 65. More Crazy Stuff Spring 3.0 MVC Annotation Access to:   Headers  Cookies 59
  • 66. Working with Session Spring 3.0 MVC Session Attribute for “pet” “pet” will be added to session “pet” will be removed from session 60
  • 68. Model Attributes as Command Objects Spring 3.0 MVC Bind command object to form Bind request to command object 62
  • 69. Submitting Forms Spring 3.0 MVC 63
  • 70. Model Validation Spring 3.0 MVC Hibernate Validator   JSR-303 Bean Validation 64
  • 71. Validation Checks in Controller Spring 3.0 MVC 65
  • 72. Spring 3.0 MVC DEMO: Spring 3.0 MVC
  • 73. Summary Spring 3.0 MVC Closing and Q&A  References  Spring Framework: http://www.springsource.com/download/  community?project=Spring%20Framework Spring Docs: http://www.springsource.org/documentation  Session Source Code: http://groups.google.com/group/codemash  Please fill out the session evaluation   Ken Sipe – kensipe@gmail.com