Hibernate 和 Spring MVC 中从一个控制器访问两种服务方法
我无法从一个控制器访问 2 种服务方法。我想创建一个任务,但同时我想创建新角色并将其自动增量 id 分配给任务的 roleId(外键)。这是一对一的映射。
我可以在 simpleFormContrller 中实现它吗?我该怎么做呢?
public class CreateTaskController extends SimpleFormController {
HResourceService hrService; // Create a Service class instance.
public void setHResourceService(HResourceService hrservice) {
this.hrService = hrservice;
}
public CreateTaskController() {
setCommandClass(Task.class);
`
` @Override protected ModelAndView onSubmit(对象命令)抛出异常 {
Task task = (Task) command;
//ContactService.createContact(contact);
hrService.createTask(task);
ModelAndView mv = new ModelAndView();
mv.setViewName(getSuccessView());
mv.addObject("taskCreated", task.getDescription()); // Pass response to taskCreated view
return mv;
}
}`
I am stuck with access 2 services methods from one controller. I want to create a Task but same time I want to create new Role and assign its auto increment id to Task's roleId(foreign key). It is a one to one mapping.
Can I implement that in simpleFormContrller? And how can I do it?
public class CreateTaskController extends SimpleFormController {
HResourceService hrService; // Create a Service class instance.
public void setHResourceService(HResourceService hrservice) {
this.hrService = hrservice;
}
public CreateTaskController() {
setCommandClass(Task.class);
`
` @Override
protected ModelAndView onSubmit(Object command) throws Exception {
Task task = (Task) command;
//ContactService.createContact(contact);
hrService.createTask(task);
ModelAndView mv = new ModelAndView();
mv.setViewName(getSuccessView());
mv.addObject("taskCreated", task.getDescription()); // Pass response to taskCreated view
return mv;
}
}`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在 hibernate beans 之间有正确的关系定义,那么应该没有问题。
There should be no problem if you have correct relation definition between hibernate beans.