Action+service+DAO

来源:互联网 发布:sql server好学吗 编辑:程序博客网 时间:2024/06/05 18:11

参考来源:http://blog.csdn.net/inter_peng/article/details/41021727
1. Action/Service/DAO简介:
Action是管理业务(Service)调度和管理跳转的。
Service是管理具体的功能的。
Action只负责管理,而Service负责实施。
DAO只完成增删改查,虽然可以1-n,n-n,1-1关联,模糊、动态、子查询都可 以。但是无论多么复杂的查询,dao只是封装增删改查。至于增删查改如何去实现一个功能,dao是不管的。
2、 DAO与DTO的区别
DAO叫数据访问对象
DTO是数据传输对象
DAO通常是将非对象数据(如关系数据库中的数据)以对象的方式操纵。
DTO通常用于不同层(UI层、服务层或者域模型层)直接的数据传输,以隔离不同层,降低层间耦合

现在最基本的分层方式,结合了SSH架构。Model层就是对应的数据库表的实体类。Dao层是使用了hibernate连接数据库、操作数据库(增删改查)。Service层:引用对应的Dao数据库操作。Action层:引用对应的Service层,在这里结合Struts的配置文件,跳转到指定的页面,当然也能接受页面传递的请求数据,也可以做些计算处理。
以上的Hibernate, Struts,都需要注入到spring的配置文件中,Spring把这些联系起来,成为一个整体。

3、spring配置文件
4、web.xml

<servlet>        <description>...</description>        <servlet-name>XXServlet</servlet-name>        <servlet-class>路径</servlet-class>        <load-on-startup>1</load-on-startup>    </servlet>

贴一段英文原汁原味的解释如下:
Servlet specification:
The load-on-startup element indicates that this servlet should be loaded (instantiated and have its init() called) on the startup of the web application. The optional contents of these element must be an integer indicating the order in which the servlet should be loaded. If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses. If the value is a positive integer or 0, the container must load and initialize the servlet as the application is deployed. The container must guarantee that servlets marked with lower integers are loaded before servlets marked with higher integers. The container may choose the order of loading of servlets with the same load-on-start-up value.

翻译过来的意思大致如下:
1)load-on-startup元素标记容器是否在启动的时候就加载这个servlet(实例化并调用其init()方法)。

2)它的值必须是一个整数,表示servlet应该被载入的顺序

2)当值为0或者大于0时,表示容器在应用启动时就加载并初始化这个servlet;

3)当值小于0或者没有指定时,则表示容器在该servlet被选择时才会去加载。

4)正数的值越小,该servlet的优先级越高,应用启动时就越先加载。

5)当值相同时,容器就会自己选择顺序来加载。

所以,x,中x的取值1,2,3,4,5代表的是优先级,而非启动延迟时间。(参考其他文档)

原创粉丝点击