Previous Version |
|
Fixed date |
2004-3 |
Version Number |
1.0 |
Modifier |
Yang caigao |
J2EESoftware Development Process
DetailsSolution And HeartGet
Shenzhen Sanda Information Technology Co., Ltd. 2004-03 ContentsRecording Part 1 Preface 2nd Requirement Analysis 3rd System Design § 3.1 use case diagram § 3.2 Class Diagram § 3.3 component Diagram 4th system implementation Section 4.1 § 4.2 basic code § 4.3 Source Code Analysis § 4.4 web implementation 5th part of Program Development 6th deepen part-a practical project 7th contact me • PrefaceThanks to the powerful functions of J2EE, I gradually learned a lot of practical technologies while learning the Java language. I want to find a project to complete my functions, so we have this document. The writing ideas in this article reflect my learning history, record the author's Java learning experience, and have a profound understanding. Before starting this project, you must master the following technologies: Basic Object-Oriented Knowledge Java language Ant basic knowledge, simple use Basic knowledge of JSP and its simple usage Servlet program writing EJB program structure This article describes two projects. The first is the description of employees and departments, and the second is the query of practical databases. • Requirement AnalysisThe purpose of this project is very simple, that is, to learn how to implement J2EE/Jeb in JBoss and to understand and apply relevant technologies. This project requires the relationship between departments and employees and between them, and between departments. Requirements: Delete a department and add operations A department can be the upper-level department or a sub-department of another existing Department. Sub-departments of a department do not need to be restricted. multiple sub-departments are allowed. Employee increase and list operations Employees belong to a certain department. Staff display requires Paging You need to display these functions in some form • System DesignBased on the above analysis, we can think that there are two entities, one is department and the other is employee. Here we can design these two entities as entity beans, it is managed by containers, that is, CMP ejbs in J2EE. According to the analysis, the two instances are composed of the following fields: Department ID of the Department ID, which can be automatically generated, but because we need it in the parent class ID, we manually generate it in the Program (maxid + 1) here ). Name of the Department Detail Department description References where parentid parent class ID is ID Employee The USERID employee ID can be either a digital ID or an English ID. Realname: real employee name Nick name Idcard ID card number Birth date Email Address External Reference of the Department ID Department entity where the specified mentid is located • Use Case chart• Class chartHere, only two basic classes are shown: The EJB Entity Bean class, which can generate eight classes in the interfaces, data, and util packages. What are the other two auxiliary fa tasks that need to be completed manually? The Ade mode class can automatically generate interfaces, fa? The six classes in the Ade package. The more detailed class diagram design is generated by other tools, which cannot be drawn here. • Component Diagram• System implementation • Brief IntroductionThis project is developed using eclipse and runs on JBoss/Tomcat 3.23. It works well. The system basically follows the MVC Software Design Pattern in two aspects: one is the EJB part and the other is the Web display part. The XDoclet method is used in the EJB part to automatically generate code. Therefore, the amount of code is small and only several key classes are required. Other auxiliary classes are automatically generated by the system, which improves efficiency and productivity, it is also a concrete embodiment of the MVC principle, with a clear structure and Automatic completion of database processing. The Web Department adopts the struts architecture and is the best representative of the MVC model in Web applications. The data in the data package is the model, the JSP page is the view, and the Action servlet is the controller. The specific implementation code list is as follows: IBM. CMIP. departmentbean. Java • Basic Code/** $ ID: departmentbean. java, v 1.1 2004/03/25 00:54:03 wadmin exp $ * @ author Yang caigao * @ version $ revision: 1.1 $ */package IBM. EJB; import Java. RMI. remoteException; import Java. util. collection; import javax. EJB. ejbexception; import javax. EJB. entitybean; import javax. EJB. entitycontext; import javax. EJB. removeexception;/*** @ EJB. bean * CMP-version = "2.x" * local-JNDI-name =" departmenthomelocal "* name =" department "* primkey-field =" ID "* type =" CMP "* View -type = "local" * @ EJB. finder * method-INTF = "localhome" * query = "select object (o) from phone o" * result-type-mapping = "local" * Signature = "Java. util. collection findall () "* @ EJB. persistence * @ JBoss. persistence * datasource = "Java: /postgresds "* datasource-mapping =" PostgreSQL 7.2 "* Create-table =" true "* remove-table =" false "* read-only =" false "* List-Cache -max = "0" * Table-name = "department" * @ EJB. util generate = "physical" */public abstract class departmentbean implements entitybean {private javax. EJB. entitycontext _ entitycontext;/*** @ EJB. persistent-field * @ EJB. persistence * @ EJB. interface-method view-type = "local" * @ EJB. PK-field */public abstract Java. lang. integer GETID (); public abstract void setid (Java. lang. integer ID);/*** @ EJB. persistent-field * @ EJB. persistence * @ EJB. interface-method view-type = "local" */public abstract Java. lang. string getname ();/*** @ EJB. interface-method view-type = "local" */public abstract void setname (Java. lang. string name);/*** @ EJB. persistent-field * @ EJB. persistence * @ EJB. interface-method view-type = "local" */public abstract Java. lang. string getdetail ();/*** @ EJB. interface-method view-type = "local" */public abstract void setdetail (Java. lang. string detail);/*** @ EJB. persistent-field * @ EJB. persistence * @ EJB. interface-method view-type = "local" * @ EJB. relation * name = "department_department" * Role-name = "department-has-department2" * Target-multiple = "yes" * Target-EJB = "department" * Target-role-name = "department2-belongsto-department "* @ JBoss. relation * FK-column = "parent" * related-PK-field = "ID" * FK-constraint = "true" */public abstract Java. lang. integer getparent ();/*** @ EJB. interface-method view-type = "local" */public abstract void setparent (Java. lang. integer parent);/*** @ EJB. interface-Method * @ EJB. relation * name = "department_employee" * Role-name = "Department-has-employee" * Target-multiple = "no" * Target-EJB = "employee" * Target-role- name = "Employee-belonsto-department" ** @jboss.tar get-relation * FK-column = "inclumentid" * related-PK-field = "ID" * FK-constraint = "true "*/public abstract collection getemployee (); /*** @ EJB. interface-Method */public abstract void setemployee (Collection employee);/*** @ EJB. create-Method */Public Java. lang. integer ejbcreate (Java. lang. integer ID, Java. lang. string name, Java. lang. string detail) throws javax. EJB. createexception {setid (ID); setname (name); setdetail (detail); return NULL;} public void ejbpostcreate (Java. lang. integer ID, Java. lang. string name, Java. lang. string detail) throws javax. EJB. createexception {}/*** @ EJB. create-Method */Public Java. lang. integer ejbcreate (Java. lang. integer ID, Java. lang. string name, Java. lang. string detail, Java. lang. integer parent) throws javax. EJB. createexception {setid (ID); setname (name); setdetail (detail); setparent (parent); return NULL;} public void ejbpostcreate (Java. lang. integer ID, Java. lang. string name, Java. lang. string detail, Java. lang. integer parent) throws javax. EJB. createexception {} public void ejbactivate () throws ejbexception, RemoteException {} public void ejbload () throws ejbexception, RemoteException {} public void ejbpassivate () throws ejbexception, remoteException {} public void ejbremove () throws removeexception, ejbexception, RemoteException {} public void ejbstore () throws ejbexception, RemoteException {} public void setentitycontext (entitycontext) throws ejbexception, remoteException {This. _ entitycontext = entitycontext;} public void unsetentitycontext () throws ejbexception, RemoteException {This. _ entitycontext = NULL;} // *-struts. form // * extends = "org. apache. struts. validator. validatorform "// * include-All =" true "// datasource =" Java:/defaultds "// datasource-mapping =" hypersonic SQL "// datasource =" Java: /mssqlds "// datasource-mapping =" Ms sqlserver2000 "// datasource =" Java:/postgresds "// datasource-mapping =" PostgreSQL 7.2 "} • Source Code AnalysisThis code can automatically generate IBM. CMIP. Interfaces. departmentlocal. Java IBM. CMIP. Interfaces. departmentlocalhome. Java IBM. CMIP. Data. departmentdata. Java IBM. CMIP. util. departmentutil. Java Four files. At the same time, IBM. CMIP. EJB. departmentfacadebean. Java File, which is a fa? Ade mode, which can be automatically generated by this file IBM. CMIP. Interfaces. departmentfacade. Java IBM. CMIP. Interfaces. departmentfacadehome. Java IBM. CMIP. facade. departmentfacaderemote. Java The last file and the file in the data package constitute the client component. Another EJB employee is similar to this implementation and completes the work of this project. • Web implementationIn system implementation, Web implementation is the interface seen by the end user. To implement the functions required in requirement analysis, the Web interface uses STRUTS to implement interaction with the user. Because web page pages are UI interfaces, their programming is relatively casual and rich in forms, so the code is the largest, debugging is not easy, the most workload of the system is this. The project uses resource properties to implement a multilingual text interface, which is more practical and reflects the MVC structure mode. The system also displays the Department on the same page as the employee. Click the Department on the left and only the employee in the specified department is displayed in the employee list on the right. • Program Development Figure 1 eclipse EJB development interface
Figure 2 eclipse EJB development interface
Figure 3 eclipse system debugging Interface
Figure 4 IE browser access interface • Deepen ---- A Practical ProjectIn the last part of this article, we will introduce some practical projects. This is the j2rd-based mobile phone inquiry system. The system focuses on providing data queries, so the application is not comprehensive, but it is very practical, so it is proposed here. The customer of this project is a mobile phone user based on j21. The customer uses GPRS or CDMA 1X technology to connect to the server and perform related queries. Scenario 1: When a mobile phone user obtains a strange mobile phone number, he wants to know which city the number belongs to. The business name is "Mobile Phone; Scenario 2: When a mobile phone user obtains an Internet IP address, he wants to know where the IP address is and the service name is IP address query; Scenario 3: When mobile users use related applications, we can collect and send user-related information to the server to provide better support. This service is named information collection. Each service must save historical records. All queries and records are implemented using ejbs. HTTP connections and Servlet responses are used for interaction with mobile phones. Due to the time relationship, we will not detail it here. • Contact meIn this project, I completed the basic framework in just one week, and occasionally added some new functions later. With the continuous understanding and learning of Java, I strongly feel that Java, as an object-like language, has an undisputed advantage. In the following time, I felt that it was necessary to write such a summative article, so I spent half a day writing these words. If these texts can inspire you, contact me: Caigao@hotmail.com Caigao@vip.sina.com |