我对简单的 MVC 应用程序有疑问。
dayoff.html
<div id="dayoff_operations" class="big_box_1">
<form:form modelAttribute="dayOff" enctype="multipart/form-data" action="/dayoff.html" >
<div style="width: 50%; float: left; margin-top: 0px ">
<form:label path="forDate" ><spring:message code="dayoff.fordate.label"/></form:label>
<form:input path="ax_forDate" id="datepicker" style="width:65px" readonly="readonly"/>
</div>
<div style="width: 50%; float: right; margin-top: 0px ">
<form:label path="toDate" ><spring:message code="dayoff.todate.label"/></form:label>
<form:input path="ax_toDate" id="datepicker2" style="width:65px" readonly="readonly" />
</div>
<div style="float: left">
<form:select cssClass="more" path="dayofftype" items="${dayoffTypes.list}" itemLabel="label" itemValue="value" htmlEscape="false" cssErrorClass="errorsField"/>
<form:errors path="dayofftype" cssClass="errors"/>
</div>
<input type="submit" name="add" value="Add"/>
</form:form>
这是我的控制器:
@Controller
@RequestMapping("/dayoff")
@SessionAttributes(types = {DayOff.class})
public class DaysOffController {
private Validator validator;
@Autowired
private ReloadableResourceBundleMessageSource messages;
@ModelAttribute("dayoffTypes")
public Map<String, Object> populateDayoffTypes(Locale locale) {
return Utils.createComboMap(DayoffType.values(), messages, locale);
}
@RequestMapping(method = RequestMethod.GET)
public String setupForm(Model model) {
model.addAttribute("dayOff", new DayOff());
model.addAttribute("cur_period",SessionManager.getCurrentPeriod());
return "dayoff";
}
@RequestMapping(method = RequestMethod.POST, params = "add")
public String addNewHoliday(@ModelAttribute DayOff dayOff, BindingResult result, ModelMap model) {
System.out.println("AAA");
return "/dayoff";
}
当我单击添加按钮时出现错误 400:SRVE0295E:报告错误:出现 400,服务器控制台上没有信息。我假设它与 setupForm() 方法有关,该方法显示表单并将其粉碎以供将来提交。你能指导我吗?