Announcement Announcement Module
Collapse
No announcement yet.
RequestMapping for urls with very large numbers of GET vars Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RequestMapping for urls with very large numbers of GET vars

    say we have a simple search mapping

    Code:
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public String search(@RequestParam("q") String searchTerm) {
       //snipped
    }
    accessable via 'http://domain/search?q=mySearch'

    this is perfectly maintainable.

    however, we want to implement advanced search, where there can be large numbers of different GET vars
    eg 'http://domain/search/advanced?field1=value1&field2..N=value2..valueN'

    to me it seems like this could become quite a headache, in terms of maintainence and readability to have eg.
    Code:
    @RequestMapping(value = "/search/advanced", method = RequestMethod.GET)
    public String advancedSearch(@RequestParam("field1") String field1, ..@RequestParam("fieldN") String fieldN) {
       //snipped
    }
    is there a way to be able to rather have something like
    Code:
    @RequestMapping(value = "/search/advanced", method = RequestMethod.GET)
    public String advancedSearch(AdvancedSearchObject advancedSearchObject) {
       //snipped
    }
    that would allow us to still have transparent/distributable URLs?

    thanks in advance
    shaine

  • #2
    You already wrote your own solution... As long as the getter/setter pairs match the object they will be bound. I strongly suggest a read of the reference guide especially the part covering web and especially forms.

    Comment

    Working...
    X