将 url 连接到 spring mvc 中的控制器 class

Connect url to controller class in spring mvc

我在视图部分使用 Thymeleaf 和 HTML。并且 spring 3. 有一个单选按钮列表,您应该 select 只有一个。我正在验证使用

                `<script th:inline="javascript">
                    /*<![CDATA[*/
                          function choose_report_kind (form_name) {
                              var form = document.forms[form_name];
                              var group = form.elements['report_kind'];

                              var report_kind;
                              for (var i = 0; i < group.length; i++) {
                                  if (group[i].checked == true) {
                                      report_kind = group[i].value;
                                  }
                              }

                              var url;
                              if (report_kind == "aos") {
                                  url = "/CustomReports?section=choose_organization";
                              }
                              else if (report_kind == 'aos_2007') {
                                  url = "/MarriottReporting1/CustomReports/2007?section=choose_organization";
                              }
                              else if (report_kind == 'aos_2008') {
                                  url = "2008/CustomReports?section=choose_organization";
                              }
                              else if (report_kind == '2009_pulse') {
                                  url = "pulse/2009/CustomReports?section=choose_organization";
                              }
                              else {
                                  alert("You must choose a type of report to run");
                                  return;
                              }
                              window.document.location.href = url;
                          }
                          /*]]>*/
                          </script>`

我必须将此 URL 传递给我的控制器。

@RequestMapping(value="/CustomReports/{year}?section=choose_organization", method=RequestMethod.GET)
public ModelAndView customReportsHome(@RequestParam("section") String section,@PathVariable("year") String year,HttpSession session, Map<String, Object> map){
    logger.debug("INSIDE CUSTOMREPORTHOME REQUEST PARAM");
    return new ModelAndView("CustomReports");
}

但我什么也得不到,而且我收到错误提示 CustomReport not found.

我认为 RequesMapping 与 javascript 中的 url 模式不匹配。

查看那里的 4 个 url 模式.. 试试这些改变...

Javascript:

if (report_kind == "aos") {
    url = "/CustomReports/choose_organization";
} else if (report_kind == 'aos_2007') {
    url = "/MarriottReporting1/CustomReports/choose_organization?year=2007";
} else if (report_kind == 'aos_2008') {
    url = "2008/CustomReports/choose_organization?year=2008";
} else if (report_kind == '2009_pulse') {
    url = "pulse/2009/CustomReports/choose_organization?year=2009";
}

控制器:

@RequestMapping("/CustomReports/{section}")
public ModelAndView customReportsHome(@PathVariable("section") String section,@RequestParam(value="year", required = false) String year,HttpSession session, Map<String, Object> map){
    logger.debug("INSIDE CUSTOMREPORTHOME REQUEST PARAM");
    return new ModelAndView("CustomReports");
}