Spring 3 MVC CodeMash 2009

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

5 comments

Comments 1 - 5 of 5 previous next Post a comment

Post a comment
Embed Video
Edit your comment Cancel

9 Favorites

Spring 3 MVC CodeMash 2009 - Presentation Transcript

  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
  17. Spring 3.0 MVC Spring MVC
  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
  67. Spring 3.0 MVC Spring Forms
  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

+ kensipekensipe, 10 months ago

custom

7148 views, 9 favs, 6 embeds more stats

Spring 3 MVC presented at Codemash 2009. If you wa more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 7148
    • 7110 on SlideShare
    • 38 from embeds
  • Comments 5
  • Favorites 9
  • Downloads 317
Most viewed embeds
  • 20 views on http://blog.csdn.net
  • 11 views on http://knitinr.blogspot.com
  • 4 views on http://static.slidesharecdn.com
  • 1 views on http://nagarjunazblog.blogspot.com
  • 1 views on http://devmemo.com

more

All embeds
  • 20 views on http://blog.csdn.net
  • 11 views on http://knitinr.blogspot.com
  • 4 views on http://static.slidesharecdn.com
  • 1 views on http://nagarjunazblog.blogspot.com
  • 1 views on http://devmemo.com
  • 1 views on http://stevedaly.blogspot.com

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories