In a Spring controller, can I have a method called based on the number of request parameters?

前端 未结 2 2079
小蘑菇
小蘑菇 2021-02-08 03:36

I\'ve been retrofitting an existing webapp with Spring. Clearly it\'s easier to start with Spring than to add it on later.

We have servlets that can take multiple reque

2条回答
  •  难免孤独
    2021-02-08 04:17

    Your request mapping needs to map an actual URL rather then just the HTTP method. You can also put required params on a per method basis like so...

    @RequestMapping(value="/doSomething", method=RequestMethod.GET, params=["prod", "owner"])
    public ModelAndView doIt(@RequestParam("prod") int prod,
                             @RequestParam("owner") int owner,
                             Model model)
    {
      ModelAndView mav = new ModelAndView();
      mav.setViewName("jsonView");
      return mav;
    }
    

提交回复
热议问题