0

我知道,类似的问题在这里被提出了好几次,但是所有这些帖子都没有帮助我,我仍然无法解决它。

这是我的控制器的一部分:

@RequestMapping("/contacts") 
@Controller 
public class ContactController {
final Logger logger = LoggerFactory.getLogger(ContactController.class); 

@Autowired
private ContactService contactService;

@Autowired 
MessageSource messageSource;

@RequestMapping(value = "/{id}", params = "form", method = RequestMethod.GET) 
public String updateForm(@PathVariable ("id") Long id, Model uiModel) { 
    uiModel.addAttribute("employee", employeeService.findById(id)); 
    logger.info("Updating employee form, id: " + id);       

    return "staff/update";
}

@RequestMapping(value = "/{id}", params = "form", method = RequestMethod.POST) 
public String update(@ModelAttribute("employee") Employee employee, BindingResult  bindingResult, Model uiModel, HttpServletRequest httpServletRequest, RedirectAttributes redirectAttributes, Locale locale) { 

logger.info("Updating employee");
if (bindingResult.hasErrors()) { 
    uiModel.addAttribute("message", new Message("error", messageSource.getMessage("employee_save_fail", new Object[]{}, locale))); 
uiModel.addAttribute("employee", employee);

return "staff/update"; 
}

uiModel.asMap().clear(); 
redirectAttributes.addFlashAttribute("message", new Message("success", messageSource.getMessage("employee_save_success", new Object[]{}, locale)));
employeeService.update(employee); 

return "redirect:/staff/" + UrlUtil.encodeUrlPathSegment(employee.getId().toString(), httpServletRequest); 
}

这是我的 edit.jspx 的一部分:

<form:form modelAttribute="emlpoyee" id="employeeUpdateForm" method="post">
    <c:if test="${not empty message}"> 
        <div id="message" class="${message.type}">${message.message}</div> 
    </c:if> 

    <form:hidden path="firstName" />
    <form:hidden path="lastName" /> 
    <form:hidden path="salary" /> 
    <form:hidden path="birthDate" /> 
    <form:hidden path="departmentId" /> 
    <form:hidden path="active" /> 

    <button type="submit">Save</button>
        <button type="reset">Reset</button>
</form:form> 

无论放在那里 form:input path=.... 或 form:label path=.... 标签,结果都是一样的:(。

补充类 Message 和 UrlUtil 简单明了。Employee 类具有所有必需的 getter 和 setter,并且它们具有正确的名称和签名。

updateForm 方法工作得很好。

当我评论所有这些表单时:隐藏标签开始正常工作,我得到带有两个按钮的屏幕......但实际上我需要在那里有很多输入。

我将不胜感激任何帮助或帮助。

4

1 回答 1

1
<form:form modelAttribute="emlpoyee"

应该

<form:form modelAttribute="employee"

一定?

于 2013-06-12T12:01:28.870 回答