在另一个实体内使用DAO和实体参考中使用DAO是一个架构问题吗?
我正在使用MVC-Architecture(JSP+Servlets+MySql& amp; no Orm-frameWorks)在Java Web应用程序上工作,并且我有下一个数据库:数据库。
我想在我的JSP视图上创建JSTL Core lib的表格,看起来像:
接收式 | ServiceName | 接收年份 | YourMaster | 状态 | DateTime |
---|---|---|---|---|---|
1 | Haircut | 1 Haircut 20 Usd | Peter Anderson | New | 17.06.2022 10:00, |
所以我决定进行下一个实体和DAO建筑:
这是我在数据库中可接待的实体。
public class Reception extends BaseEntity {
private Service service;
private User master;
private User client;
private int cost;
private LocalDateTime receptionDateTime;
private Status status;
// getters setters
}
我担心接收中包含另一个实体(服务,用户),这使我在另一个dao中使用dao:
public class ReceptionDAO implements GenericDAO<Reception> {
public Reception mapReception(ResultSet resultSet) throws SQLException, DaoException {
Reception reception = new Reception();
long receptionId = resultSet.getLong("id");
long serviceId = resultSet.getLong("service_id");
long masterId = resultSet.getLong("master_id");
long clientId = resultSet.getLong("client_id");
int cost = resultSet.getInt("cost");
LocalDateTime dateTime =resultSet.getTimestamp("reception_date_time").toLocalDateTime();
int statusId = resultSet.getInt("status_id");
UserDAO userDAO = new UserDAO();
ServiceDAO serviceDAO = new ServiceDAO();
reception.setId(receptionId);
reception.setService(serviceDAO.findById(serviceId));
reception.setMaster(userDAO.findById(masterId));
reception.setClient(userDAO.findById(clientId));
reception.setCost(cost);
reception.setReceptionDateTime(dateTime);
reception.setStatus(Status.getStatus(statusId));
return reception;
}
所以我有几个问题:
- 在另一个实体中使用实体对象参考是一个好习惯吗?
- 在另一个dao中使用dao还是不良的做法是有意义的吗?
- 如果这是一个很大的问题,请告诉我如何解决这个问题。
I am working on java web application with MVC-architecture (JSP+SERVLETS+MYSQL && NO ORM-FRAMEWORKS) and I have next database: database.
I wanted to create table by JSTL core lib on my JSP-view that looks like that:
ReceptionID | ServiceName | ReceptionCost | YourMaster | Status | DateTime |
---|---|---|---|---|---|
1 | Haircut | 20 USD | Peter Anderson | New | 17.06.2022 10:00 |
So i decided to make next Entity and DAO architecture:
This is my Entity for ReceptionTable in database.
public class Reception extends BaseEntity {
private Service service;
private User master;
private User client;
private int cost;
private LocalDateTime receptionDateTime;
private Status status;
// getters setters
}
I am worried about Reception contains another Entities (Service, User) and it makes me to use DAO inside another DAO:
public class ReceptionDAO implements GenericDAO<Reception> {
public Reception mapReception(ResultSet resultSet) throws SQLException, DaoException {
Reception reception = new Reception();
long receptionId = resultSet.getLong("id");
long serviceId = resultSet.getLong("service_id");
long masterId = resultSet.getLong("master_id");
long clientId = resultSet.getLong("client_id");
int cost = resultSet.getInt("cost");
LocalDateTime dateTime =resultSet.getTimestamp("reception_date_time").toLocalDateTime();
int statusId = resultSet.getInt("status_id");
UserDAO userDAO = new UserDAO();
ServiceDAO serviceDAO = new ServiceDAO();
reception.setId(receptionId);
reception.setService(serviceDAO.findById(serviceId));
reception.setMaster(userDAO.findById(masterId));
reception.setClient(userDAO.findById(clientId));
reception.setCost(cost);
reception.setReceptionDateTime(dateTime);
reception.setStatus(Status.getStatus(statusId));
return reception;
}
So i have a several questions:
- Is it good practice to use entity-object reference in another entity?
- Does it make sense to use DAO inside another DAO or maybe it is a bad practice?
- If it is a very big problem, tell me how can i solve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论