我有一个简单的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()方法有关,该方法显示表单并将其粉碎以供将来提交。你能给我指点一下吗?
错误400:SRVE0295E也发生在MVC不能用HTML表单中的值填充@ModelAttribute Form
时。
- 类
Form
具有原始属性int someCount
- 你的HTML表单有
<input>
分配值给这个基本属性 - 用户为
<input>
输入空值(null
)
您不应该使用诸如int
、boolean
、float
等基本类型
setupForm和addnewholday的返回语句是不同的。我假定您希望从两者返回相同的视图名。如您所见,为了提交表单,我假设"/dayoff"的addNewHoliday返回值实际上应该是"dayoff"