我是 spring 新手,我设法从 JSP 视图中的表单收集数据并将我的表单提交给控制器。从视图获取的数据中,我正在实例化一个模型对象,该对象还包含其他模型对象:
@RequestMapping(value = "/updateEntry", method = RequestMethod.GET)
public RedirectView updateAction(ModelAndView model,
@RequestParam(value = "name", defaultValue = "none") String selectedWaveName,
@RequestParam(value = "id", defaultValue = "-1") int id,
@RequestParam(value = "function", defaultValue = "none") String function,
@RequestParam(value = "evidence", defaultValue = "none") String evidence,
@RequestParam(value = "action", defaultValue = "none") String action,
@RequestParam(value = "topicId", defaultValue = "-1") int topicId,
@RequestParam(value = "topic", defaultValue = "none") String topic,
@RequestParam(value = "topicDesc", defaultValue = "none") String topicDesc,
@RequestParam(value = "waveId", defaultValue = "-1") int waveId,
@RequestParam(value = "waveStart", defaultValue = "none") String waveStart,
@RequestParam(value = "waveEnd", defaultValue = "none") String waveEnd)
throws ParseException {
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
Date dateStart = formatter.parse(waveStart);;
Date dateEnd = formatter.parse(waveEnd);
waveDAO.updateFormResults(new FormResults(id,
new Topic(topicId, topic, topicDesc),
new Wave(waveId, selectedWaveName, dateStart, dateEnd),
evidence, action, function));
return new RedirectView("/hr/?name=" + selectedWaveName);
}
如何使用 @ModelAttribute 用更少的行替换整个 @RequestParam 行?我是否还需要将 @ModelAttribute 注释添加到模型类(FormResults、Topic、Wave)?
谢谢。