我有一个控制器方法:
@RequestMapping(value = "/editComment/{id}", method = RequestMethod.GET)
public ModelAndView showOfficeComment(@RequestParam(value="id", required = false) Long id) {
Office office;
office = officeServiceImpl.find(id);
ModelAndView result = new ModelAndView("editComment", "command", office);
return result;
}
当我在浏览器中将地址放在最后的ID(... editComment / 100)时,我收到以下错误消息:
java.lang.IllegalArgumentException: id to load is required for loading
我有以下完美运作的方法:
@RequestMapping(value = "/officeForm/{id}", method=RequestMethod.GET)
public ModelAndView showOfficeForm(@RequestParam(value="id", required = false) Long id) {
Office office;
if (id == null) {office = new Office();}
else {office = officeServiceImpl.find(id);}
office.setDepartments(new ArrayList<Department>());
List<Department> departments = departmentServiceImpl.findAll();
ModelAndView result = new ModelAndView("officeForm", "command", office);
result.addObject("departments", departments);
return result;
}
有人可以解释这里发生了什么吗?感谢。