我使用Thymeleaf和HTML作爲視圖部分。和春天3.有一個單選按鈕的列表,你應該只選擇一個。我驗證使用在url中將url連接到控制器類mvc
`<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模式。 – Sachin
你能幫我解釋一下它應該如何,因爲我對此很陌生? – nitheesh
看看你在那裏的4個url模式..我認爲這個@RequestMapping對我更有意義.. @RequestMapping(「/ CustomReports/{section})'然後使用'@RequestParam(」year「)'和'@PathVariable(「section」)'來獲取它們 – Sachin