模型和 DAO 应该如何交互?我正在组装一个简单的登录模块,但我不确定将“业务逻辑”放在哪里。如果我将逻辑与数据一起放入模型中,我将如何访问逻辑?
目前,我有:
- A controller that receives form data
- A model that is a simple reflection of a db table
- A DAO that using hibernate performs a simple select query, based on the form parameters received by the controller.
最佳答案
Controller 必须找到/加载与请求匹配的业务对象并执行它。 Strategy Pattern对此很有用。业务对象必须获取 DAO 的句柄和模型来执行该流程。
例如(伪,在前端 Controller servlet 内)
public void process(request, response) {
View view = new View(request, response);
Action action = ActionFactory.getAction(request);
if (action != null) action.execute(view);
view.navigate();
}
关于java - 模型(在 MVC 中)和 DAO 应该如何交互?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1684345/