Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-7543

Automatically expose @PathVariables in the Model

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 3.0.4
    • Fix Version/s: 3.1 M2
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      It'd be nice instead of having to do this:

      @RequestMapping(value="/edit/{slug}", method=RequestMethod.GET)
      public String getEditAppForm(@PathVariable String slug, Account account, Model model) {
          model.addAttribute(connectedAppRepository.getAppForm(account.getId(), slug));
          model.addAttribute("slug", slug);
          return "develop/apps/edit";
      }
      

      ... and using ${slug} in my template to access the @PathVariable value, I could simply do:

      @RequestMapping(value="/edit/{slug}", method=RequestMethod.GET)
      public String getEditAppForm(@PathVariable String slug, Account account, Model model) {
          model.addAttribute(connectedAppRepository.getAppForm(account.getId(), slug));
          return "develop/apps/edit";
      }
      

      and reference something automatically exposed like ${pathVars.slug} in my template.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              kdonald Keith Donald
              Last updater:
              Spring Issuemaster
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 20 weeks, 3 days ago