Spring MVC Basics
Upcoming SlideShare
Loading in...5
×
 

Spring MVC Basics

on

  • 8,688 views

A short presentation about the basics of spring

A short presentation about the basics of spring

Statistics

Views

Total Views
8,688
Views on SlideShare
7,167
Embed Views
1,521

Actions

Likes
5
Downloads
217
Comments
0

4 Embeds 1,521

http://java.dzone.com 1518
http://www.dzone.com 1
http://translate.googleusercontent.com 1
http://webcache.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Spring MVC Basics Spring MVC Basics Presentation Transcript

    • 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 ?