我的简单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()方法,该方法显示表单并将其压缩到未来的提交。你能指导我吗?
答案 0 :(得分:4)
错误400:当MVC无法使用HTML表单中的值填充@ModelAttribute Form
时,也会发生SRVE0295E。
例如:
Form
具有原始属性int someCount
<input>
为此原始属性赋值null
<input>
)
您不应使用int
,boolean
,float
等原始类型。
答案 1 :(得分:0)
setupForm和addNewHoliday的return语句不同。我认为你想要从两者返回相同的视图名称。正如您可以看到表单以提交它,我假设addNewHoliday返回值“/ dayoff”实际上应该是“dayoff”