一个小型网站中的层职责设计,请问是否合理
这个网站的主要功能是新闻发布,投票管理,一些政策信息的发布,新闻版块的管理.
项目使用struts+hibernate3.0开发
项目中分层是这样的
Entity(相当于DOMAIN)
DAO层
Service层.
还有 web层.web层主要是struts的action,相当于一个控制器.
在DAO层中我只写了一个包含了CRUD方法的接口暂时叫做(Service)和它的一个实现类,接口中的方法如下
interface Service{
saveOrupdate(Entity e);//Entity 是每个实体类必须实现的接口
delete(Class c,Serializable id);
List query(String hql,Map conditions);//使用hibernate HQL查询
}
针对于具体的业务要求,我在Service层中写具体的业务方法,比如:
NewsService{
Service service=new ServiceImpl();
public News readNewsById(Serializable newsId){
String hql="from news n where n.id=:id";
Map conditions=new HashMap();
conditions.put("id",conditions);
List newsList=service.query(hql,conditions);
return newsList.get(0);
}
public void deleteNewsById(Serializable id){
service.delete(News.class,id);
}
......//其余业务方法略
}
在NewsService中我没有使用任何事物机制.具体的事物是通过AOP方式实现的,这个事物处理方法是通过CGLIB中的enhancer来包装这个NewsService,然后写个方法拦截器,在NewsService中每个方法执行之前和之后开启事物和关闭事物以及捕获异常回滚等.
这个包装NewsService的类叫TransactionProxy,在struts的action中通过如下方式使用带有事物机制的NewsService
DeleteNewsAction extends Action {
public ActionForward execute(....){
NewsService newsService=
(NewsService)TransactionProxy(NewsService.class);
.....
}
}
以上是我的代码,不知道大家对这样的项目结构有什么看法;本人期待大家的意见,谢谢