struts+dao的设计模式
DAO(DataAccessObject)的设计模式是J2EE中主要的设计模式.选用DAO的设计的好处:用户不需求认识底层的详细终结,只需求操作接口;一起终结了前台和后后台的分别;(DAO中只需求操作对象);有利于代码的重用.(假如用户需求增加新的功能时候,我只需求在DAO这接口中增加的笼统的方法,然后在DAOImpl中终结用户所增加的功能,就能很好的终结增加用户功能的.)DAO的整体设计过程:JSP---gt;DAO工厂--gt;详细终结类--gt;终结数据库的详细操作1.终结数据库的连接类(DataBaseConnection.java)packageorg.zhao.DataBaseConnection.dbc;importjava.sql.;publicclassDataBaseConnection{privatefinalStringDBDRIVER=com.mysql.jdbc.Driver;privatefinalStringDBURL=jdbc:mysql://localH/OST:3306/student;privatefinalStringDBUSER=root;privatefinalStringDBPASSWORD=root;privateConnectionconn=null;publicDataBaseConnection(){try{Class.forName(DBDRIVER);//conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);conn=DriverManager.getConnection(jdbc:mysql://localH/OST:3306/student?user=rootpassword=root);}catch(Exceptione){}}publicConnectiongetConnection(){returnthis.conn;}publicvoidclose(){try{this.conn.close();}catch(SQLExceptione){e.printStackTrace();}}}2.定义项目所要终结的功能......
struts+dao的设计模式.txt
(The design pattern of DAO (DataAccessObject) is the main design pattern in J2EE. The advantages of choosing DAO design: users do not need to know the detailed termination of the underlying layer, but only need to operate the interface; the distinction between the foreground and the background is terminated together; (in DAO only Requirement operation object); it is conducive to code reuse. (If the user needs to add new functions, I only need the general methods added in the DAO interface, and then terminate the user-added functions in DAOImpl, it will be very good. The terminal of the terminal increases user functions.) The overall design process of DAO: JSP---gt; DAO factory --gt; detailed terminal class --gt; detailed operation of terminal database 1. Terminal database connection class (DataBaseConnection.java) packageorg.zhao.DataBaseConnection.dbc;importjava.sql.
;publicclassDataBaseConnection{privatefinalStringDBDRIVER=com.mysql.jdbc.Driver;privatefinalStringDBURL=jdbc:mysql://localH/OST:3306/student;privatefinalStringDBUSER=root;privatefinalStringDBPASSWORD=root;privateConnectionconn=null;publicDataBaseConnection(){try{Class.forName (DBDRIVER);//conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);conn=DriverManager.getConnection(jdbc:mysql://localH/OST:3306/student?user=rootpassword=root);}catch(Exceptione ){}}publicConnectiongetConnection(){returnthis.conn;}publicvoidclose(){try{this.conn.close();}catch(SQLExceptione){e.printStackTrace();}}}2. Define the function to be terminated by the project ......
The design pattern of struts dao.txt)
页:
[1]