当用户将记录插入数据库时,我有一个表单,他们可能希望同时创建一条新记录,他们可以单击一个新按钮。我定义了一个控制器来接受此命令,并仅在填充列表框的情况下向用户返回一个空白视图,但是该视图不会返回空白,它具有来自先前插入数据库的数据。
代码:
用户选择以下按钮
<button class="btn" value="new" onclick="submitPage('${pageContext.request.contextPath}/crime_registration_new.htm');" type="button" >New</button>
控制器方法:
我想摆脱旧的犯罪对象
@RequestMapping(value="crime_registration_new.htm", method = RequestMethod.POST)
public ModelAndView loadNew(HttpServletRequest request,
HttpServletResponse response,
@ModelAttribute Crime crime,
Model model) throws Exception {
try{
logger.debug("In Crime Registration Controller");
myCriminalList.put("dbcriminalList", this.citizenManager.getListOfCriminals());
myVictimList.put("dbvictimList", this.citizenManager.getListOfVictims());
myStatusList.put("statusList", this.statusManager.getStatusList());
myCrimeCategoryList.put("crimeCategoryList", this.crimeCategoryManager.getCrimeCategoryList());
myCrimeLevelList.put("crimeLevelList", this.crimeLevelManager.getCrimeLevelList());
myOfficerList.put("investigatingOfficerList", this.officerManager.getOfficersList());
model.addAttribute("dbcriminals", myCriminalList);
model.addAttribute("dbvictims", myVictimList);
model.addAttribute("status", myStatusList);
model.addAttribute("crimeCategory", myCrimeCategoryList);
model.addAttribute("crimeLevel",myCrimeLevelList);
model.addAttribute("officers",myOfficerList);
model.addAttribute("crimeRecordNoStatus", "true");
model.addAttribute("crimeRecordNoStatus", "true");
model.addAttribute("save", "enabled");
return new ModelAndView("crime_registration");
}catch(Exception e){
logger.debug("Exception In CrimeRegistration Controller : " + e.getMessage());
return new ModelAndView("crime_registration");
}
}