Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Get all params from URL in Controller

I have in front end a form where the user selects the year and one or more months from a list of months. These params will be sent to Controller as Get Method. Given an URL like this:

..../{year}/{months}/excel/

Where months would be a variable list of the months selected, i.e [01,02,10].

How I receive all parameters in the Controller? Here's my controller so far:

    @RequestMapping(value = "/{year}/{months}/excel/", method = RequestMethod.GET, produces = EXCEL_FORMAT_HEADER)
    public @ResponseBody
    ModelAndView getRankingByYearExcel(@PathVariable("year") Integer year,
                                       @RequestParam Map<String, Object> months)
 {...}
like image 484
YanetP1988 Avatar asked May 14 '26 04:05

YanetP1988


1 Answers

I did it like this and worked, declaring months as array of Strings:

@RequestMapping(value = "/{year}/excel/", method = RequestMethod.GET, produces = EXCEL_FORMAT_HEADER)
public @ResponseBody
ModelAndView getRankingByYearExcel(@PathVariable("year") Integer year,
                                   @RequestParam String[] months)

And in URL sent variable months as array of strings:

../2016/excel/?months=1,3,12

Thanks for guiding me in this direction

like image 66
YanetP1988 Avatar answered May 15 '26 19:05

YanetP1988