重载Post RequestMapping

时间:2016-07-06 10:21:07

标签: spring spring-mvc spring-boot

我正在尝试重载Spring控制器的RequestMapping。控制器获取POST作为请求方法,我需要传递不同的参数来重载它。

如何在不更改网址的情况下执行此操作?

{{1}}

1 个答案:

答案 0 :(得分:2)

您可以在注释params中使用@RequestParam选项,如下所示:

@RequestMapping(method = RequestMethod.POST, value = "/windparks/import/error", params = {"locale", "authenticatedUser", "regList", "regulations", "windparkId"})
public ModelAndView handleFileUploadError(Locale locale, @AuthenticationPrincipal SpringUser authenticatedUser, List<RegulationEvent> regList, @RequestParam("regulations") MultipartFile regulations, RedirectAttributes redirectAttributes, @PathVariable String windparkId) throws IOException, WindSpeedInterpolator.TimeSeriesMismatchException, SAXException {
    ModelAndView view = new ModelAndView("uis/windparks/parkdetail");

    view.addObject("failedEvents", regList);
    view.addObject("windparkId", windparkId);


    return view;
}

@RequestMapping(method = RequestMethod.POST, value = "/windparks/import/error", params = {"locale", "authenticatedUser", "windparkId"})
public ModelAndView handleFileUploadError(Locale locale, @AuthenticationPrincipal SpringUser authenticatedUser, RedirectAttributes redirectAttributes, @PathVariable String windparkId) throws IOException, WindSpeedInterpolator.TimeSeriesMismatchException, SAXException {
    ModelAndView view = new ModelAndView("uis/windparks/parkdetail");

    view.addObject("windparkId", windparkId);


    return view;
}

可能不适合您,但您可以在Spring中查看params手册。