SlideShare a Scribd company logo
Spring-MVC Basics Bozhidar Bozhanov Bulgarian Association of Software Developers www.devbg.org http://techblog.bozho.net
MVC Source: http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html
Model Map<String, Object> Populated by controllers Contains all data needed by the „view“ Not containing business logic model.addAttribute(&quot;orders&quot;,  orderService.getDailyOrders(user)); model.addAttribute(&quot;period&quot;, Period.DAILY);
View HTML, XML, RSS, PDF, etc... JSP, Freemarker, Velocity, etc Direct access to the model <span> ${latestOrder.date} <span> <input type=&quot;text&quot;  value=&quot; ${order.name} &quot; />
Controller Gathers input parameters and coordinates the back-end process Front controller vs controller @Controller RESTful URLs, request-process-forward, @RequestMapping Method=Action Unit-test friendly Pluggable mechanism for argument resolution
Controller Gathers input parameters and coordinates the back-end process Front controller vs controller @Controller RESTful URLs, request-process-forward, @RequestMapping Method=Action Unit-test friendly Pluggable mechanism for argument resolution
Controller @Controller @RequestMapping(&quot;/users&quot;) public   class  UserController { @Inject   private  UserService  service ; @RequestMapping(&quot;/login&quot;) public  String login(@RequestParam String username, @RequestParam String pass){ User u = service.login(username, pass); return &quot;welcomePage&quot;; } @RequestMapping(&quot;/view/{username}&quot;) public  String view(@PathVariable String username){ User u = service.find(username); ... return &quot;userPage&quot;; } }
Controller arguments @RequestParam, @PathVariable POJO – arbitrary java object that gets populated with request values @Valid – to enforce validation of the POJO BindingResult – to access the results of binding and validation Model, ModelMap, Map<String, ?> - acces to the model object Raw HttpServletRequest, response, session Locale, @RequestHeader, @RequestBody,....
Controllers – return types String, View, ModelAndView – use a “view“ @ResponseBody – any object @Controller @RequestMapping(&quot;/users&quot;) public   class  UserController { @Inject   private  UserService  service ; @RequestMapping(value=&quot;/ajaxView&quot;  consumes=&quot;application/json&quot;) @ResponseBody public  User view(@RequestParam String username){ User u = service.find(username); return user; } }
More... Interceptors Exception handling Binding and validation customization Static resource handling Caching configuration Locale and theme resolution Multipart handling Flash scope, conversation scope (web flow)
The lifecycle once again Source: http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html
Demo (spring mvc showcase)
Resources http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html http://static.springsource.org/docs/petclinic.htmlhttps://github.com/SpringSource/spring-mvc-showcase
Questions ?
Ad

Recommended

Spring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topics
Guy Nir
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVC
Guy Nir
 
Spring MVC 3.0 Framework
Spring MVC 3.0 Framework
Ravi Kant Soni ([email protected])
 
Spring MVC
Spring MVC
Emprovise
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
Spring Web MVC
Spring Web MVC
zeeshanhanif
 
Introduction to Spring MVC
Introduction to Spring MVC
Richard Paul
 
Spring MVC Architecture Tutorial
Spring MVC Architecture Tutorial
Java Success Point
 
Spring MVC
Spring MVC
yuvalb
 
Spring MVC Annotations
Spring MVC Annotations
Jordan Silva
 
Spring Portlet MVC
Spring Portlet MVC
John Lewis
 
Spring mvc
Spring mvc
Guo Albert
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
Tuna Tore
 
Spring 4 Web App
Spring 4 Web App
Rossen Stoyanchev
 
Spring MVC 3.0 Framework (sesson_2)
Spring MVC 3.0 Framework (sesson_2)
Ravi Kant Soni ([email protected])
 
Spring Framework - MVC
Spring Framework - MVC
Dzmitry Naskou
 
Spring MVC
Spring MVC
Aaron Schram
 
Spring mvc
Spring mvc
Hamid Ghorbani
 
Struts,Jsp,Servlet
Struts,Jsp,Servlet
dasguptahirak
 
MVC on the server and on the client
MVC on the server and on the client
Sebastiano Armeli
 
Spring Mvc Rest
Spring Mvc Rest
Craig Walls
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
BG Java EE Course
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
Michał Orman
 
Spring framework in depth
Spring framework in depth
Vinay Kumar
 
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
John Lewis
 
Spring mvc
Spring mvc
Harshit Choudhary
 
Spring MVC Intro / Gore - Nov NHJUG
Spring MVC Intro / Gore - Nov NHJUG
Ted Pennings
 
quickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvc
jorgesimao71
 
Spring MVC - The Basics
Spring MVC - The Basics
Ilio Catallo
 

More Related Content

What's hot (19)

Spring MVC
Spring MVC
yuvalb
 
Spring MVC Annotations
Spring MVC Annotations
Jordan Silva
 
Spring Portlet MVC
Spring Portlet MVC
John Lewis
 
Spring mvc
Spring mvc
Guo Albert
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
Tuna Tore
 
Spring 4 Web App
Spring 4 Web App
Rossen Stoyanchev
 
Spring MVC 3.0 Framework (sesson_2)
Spring MVC 3.0 Framework (sesson_2)
Ravi Kant Soni ([email protected])
 
Spring Framework - MVC
Spring Framework - MVC
Dzmitry Naskou
 
Spring MVC
Spring MVC
Aaron Schram
 
Spring mvc
Spring mvc
Hamid Ghorbani
 
Struts,Jsp,Servlet
Struts,Jsp,Servlet
dasguptahirak
 
MVC on the server and on the client
MVC on the server and on the client
Sebastiano Armeli
 
Spring Mvc Rest
Spring Mvc Rest
Craig Walls
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
BG Java EE Course
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
Michał Orman
 
Spring framework in depth
Spring framework in depth
Vinay Kumar
 
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
John Lewis
 
Spring mvc
Spring mvc
Harshit Choudhary
 
Spring MVC
Spring MVC
yuvalb
 
Spring MVC Annotations
Spring MVC Annotations
Jordan Silva
 
Spring Portlet MVC
Spring Portlet MVC
John Lewis
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
Tuna Tore
 
Spring Framework - MVC
Spring Framework - MVC
Dzmitry Naskou
 
MVC on the server and on the client
MVC on the server and on the client
Sebastiano Armeli
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
BG Java EE Course
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
Michał Orman
 
Spring framework in depth
Spring framework in depth
Vinay Kumar
 
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
John Lewis
 

Similar to Spring MVC Basics (20)

Spring MVC Intro / Gore - Nov NHJUG
Spring MVC Intro / Gore - Nov NHJUG
Ted Pennings
 
quickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvc
jorgesimao71
 
Spring MVC - The Basics
Spring MVC - The Basics
Ilio Catallo
 
Spring 3: What's New
Spring 3: What's New
Ted Pennings
 
Spring-training-in-bangalore
Spring-training-in-bangalore
TIB Academy
 
Spring MVC introduction HVA
Spring MVC introduction HVA
Peter Maas
 
Orbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case Study
Mark Meeker
 
REST based web applications with Spring 3
REST based web applications with Spring 3
Oliver Gierke
 
Spring mvc
Spring mvc
Hui Xie
 
Spring Framework
Spring Framework
nomykk
 
What's Coming in Spring 3.0
What's Coming in Spring 3.0
Matt Raible
 
Spring mvc
Spring mvc
Pravin Pundge
 
A project on spring framework by rohit malav
A project on spring framework by rohit malav
Rohit malav
 
Multi Client Development with Spring - Josh Long
Multi Client Development with Spring - Josh Long
jaxconf
 
Spring training
Spring training
TechFerry
 
Spring_Course_Content
Spring_Course_Content
MV Solutions
 
Spring MVC Framework
Spring MVC Framework
Hùng Nguyễn Huy
 
Session 46 - Spring - Part 4 - Spring MVC
Session 46 - Spring - Part 4 - Spring MVC
PawanMM
 
Spring mvc
Spring mvc
Deepak Bhagat
 
Spring MVC framework features and concepts
Spring MVC framework features and concepts
AsmaShaikh478737
 
Spring MVC Intro / Gore - Nov NHJUG
Spring MVC Intro / Gore - Nov NHJUG
Ted Pennings
 
quickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvc
jorgesimao71
 
Spring MVC - The Basics
Spring MVC - The Basics
Ilio Catallo
 
Spring 3: What's New
Spring 3: What's New
Ted Pennings
 
Spring-training-in-bangalore
Spring-training-in-bangalore
TIB Academy
 
Spring MVC introduction HVA
Spring MVC introduction HVA
Peter Maas
 
Orbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case Study
Mark Meeker
 
REST based web applications with Spring 3
REST based web applications with Spring 3
Oliver Gierke
 
Spring mvc
Spring mvc
Hui Xie
 
Spring Framework
Spring Framework
nomykk
 
What's Coming in Spring 3.0
What's Coming in Spring 3.0
Matt Raible
 
A project on spring framework by rohit malav
A project on spring framework by rohit malav
Rohit malav
 
Multi Client Development with Spring - Josh Long
Multi Client Development with Spring - Josh Long
jaxconf
 
Spring training
Spring training
TechFerry
 
Spring_Course_Content
Spring_Course_Content
MV Solutions
 
Session 46 - Spring - Part 4 - Spring MVC
Session 46 - Spring - Part 4 - Spring MVC
PawanMM
 
Spring MVC framework features and concepts
Spring MVC framework features and concepts
AsmaShaikh478737
 
Ad

More from Bozhidar Bozhanov (20)

Откриване на фалшиви клетки за подслушване
Откриване на фалшиви клетки за подслушване
Bozhidar Bozhanov
 
Wiretap Detector - detecting cell-site simulators
Wiretap Detector - detecting cell-site simulators
Bozhidar Bozhanov
 
Антикорупционен софтуер
Антикорупционен софтуер
Bozhidar Bozhanov
 
Nothing is secure.pdf
Nothing is secure.pdf
Bozhidar Bozhanov
 
Elasticsearch - Scalability and Multitenancy
Elasticsearch - Scalability and Multitenancy
Bozhidar Bozhanov
 
Encryption in the enterprise
Encryption in the enterprise
Bozhidar Bozhanov
 
Blockchain overview - types, use-cases, security and usabilty
Blockchain overview - types, use-cases, security and usabilty
Bozhidar Bozhanov
 
Електронна държава
Електронна държава
Bozhidar Bozhanov
 
Blockchain - what is it good for?
Blockchain - what is it good for?
Bozhidar Bozhanov
 
Algorithmic and technological transparency
Algorithmic and technological transparency
Bozhidar Bozhanov
 
Scaling horizontally on AWS
Scaling horizontally on AWS
Bozhidar Bozhanov
 
Alternatives for copyright protection online
Alternatives for copyright protection online
Bozhidar Bozhanov
 
GDPR for developers
GDPR for developers
Bozhidar Bozhanov
 
Политики, основани на данни
Политики, основани на данни
Bozhidar Bozhanov
 
Отворено законодателство
Отворено законодателство
Bozhidar Bozhanov
 
Overview of Message Queues
Overview of Message Queues
Bozhidar Bozhanov
 
Electronic governance steps in the right direction?
Electronic governance steps in the right direction?
Bozhidar Bozhanov
 
Сигурност на електронното управление
Сигурност на електронното управление
Bozhidar Bozhanov
 
Opensource government
Opensource government
Bozhidar Bozhanov
 
Биометрична идентификация
Биометрична идентификация
Bozhidar Bozhanov
 
Откриване на фалшиви клетки за подслушване
Откриване на фалшиви клетки за подслушване
Bozhidar Bozhanov
 
Wiretap Detector - detecting cell-site simulators
Wiretap Detector - detecting cell-site simulators
Bozhidar Bozhanov
 
Антикорупционен софтуер
Антикорупционен софтуер
Bozhidar Bozhanov
 
Elasticsearch - Scalability and Multitenancy
Elasticsearch - Scalability and Multitenancy
Bozhidar Bozhanov
 
Encryption in the enterprise
Encryption in the enterprise
Bozhidar Bozhanov
 
Blockchain overview - types, use-cases, security and usabilty
Blockchain overview - types, use-cases, security and usabilty
Bozhidar Bozhanov
 
Електронна държава
Електронна държава
Bozhidar Bozhanov
 
Blockchain - what is it good for?
Blockchain - what is it good for?
Bozhidar Bozhanov
 
Algorithmic and technological transparency
Algorithmic and technological transparency
Bozhidar Bozhanov
 
Alternatives for copyright protection online
Alternatives for copyright protection online
Bozhidar Bozhanov
 
Политики, основани на данни
Политики, основани на данни
Bozhidar Bozhanov
 
Отворено законодателство
Отворено законодателство
Bozhidar Bozhanov
 
Electronic governance steps in the right direction?
Electronic governance steps in the right direction?
Bozhidar Bozhanov
 
Сигурност на електронното управление
Сигурност на електронното управление
Bozhidar Bozhanov
 
Биометрична идентификация
Биометрична идентификация
Bozhidar Bozhanov
 
Ad

Spring MVC Basics