gpt4 book ai didi

java - Spring 表格未在提交表格时重新填写

转载 作者:行者123 更新时间:2023-12-02 08:25:19 25 4
gpt4 key购买 nike

当我加载此表单时,国家/地区表是从包含 240 个国家/地区的数据库中填充的。如果我提交它并带有一些空的必填字段,页面将再次重新加载并显示错误消息。但我没有列出任何国家。我使用相同的代码来填充 GET 和 POST 方法上的列表 - 见下文

      <form:form commandName="student_personal_info" method="post">
<table>
<tr>
<td><form:label path="country">Country:</form:label></td>
<td><form:select path="country">
<form:option value="NONE" label=" --Select-- "></form:option>
<form:options items="${countries}"/>
</form:select>
</td>
</tr></table>
</form:form>



@RequestMapping(value = "student_personal_info", method = RequestMethod.GET)
public ModelAndView DisplayPersonalForm(ModelAndView model) {
StudentPersonalInfo personalInfo = new StudentPersonalInfo();
model.addObject("student_personal_info", personalInfo);

model.addObject("countries",getCountries());
return model;
} //this works fine

@RequestMapping(value = "student_personal_info", method = RequestMethod.POST)
public String PersonalFormSubmitted(
@ModelAttribute("student_personal_info") @Valid StudentPersonalInfo student_personal_info,
BindingResult result, ModelAndView model) {
model.addObject("countries", getCountries());
if (result.hasErrors()) {
logger.info("From student personal info, there are "
+ String.valueOf(this.getCountries().size())
+ " Countries"); //This prints 240 countries on the consule
return "student_personal_info";
}

else
return "redirect:/display_program_of_study.tsegay";
}

我的所有其他配置都工作正常

最佳答案

我猜你无法在不返回的情况下填充ModelAndView,因此你需要使用另一种参数类型:

@RequestMapping(value = "student_personal_info", method = RequestMethod.POST)        
public String PersonalFormSubmitted(
@ModelAttribute("student_personal_info") @Valid StudentPersonalInfo student_personal_info,
BindingResult result, ModelMap model) { ... }

关于java - Spring 表格未在提交表格时重新填写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4637987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com