- In combination with WebWork2 and Hibernate simplified system structure, improve development efficiency
Primer
If the narrow understanding, many times, a job running on the B / S platform is to accept the information input from the browser side. Store the database after processing, or from the database to extract data processing and format the post-pass The browser is displayed to the user. However, let the application designer is very frustrating: the browser is very weak, only information that is extremely low in complexity, such as the form of text information; the mainstream database is a relational database, does not directly store the face The field model data of the object; the application system is often designed, developed in an object-oriented manner. From the Form that can only pass the simple data type, to the object-oriented system, then to the relational database, we must cross the annoying system boundaries, that is, we must perform multiple forms of morphological conversion of the same data to implement system functions. In order to solve this problem, the system design a lot of solutions, such as: using the FormBean package from the browser to pass the simple type data (or some common type of shape, but said, or simply type, not Field model Domain model, with VO (different design is different, but the idea is the same) to make a one-to-one mapping of Tables-JavaBeans for relational databases.
In this way, the Table of the browser's FORM and relational database has been object-oriented. In a sense, it plays a function of an adapter, hidden the bottom layer of the browser's FORM and the database. Information simplifies system design and has achieved good results during a considerable period of time. However, as the complexity of business system is increased, this solution shows many flaws:
Due to the introduction of FORMBEAN, VO, the two types of Domain Object are not related to Domain Object, the developer is scattered attention to the field of object itself, and the complexity of the system has increased the system's complexity, and the system's operational efficiency is reduced, and the coupling of the system, Necessary effects have been negative. It can be considered that this is no longer the best, most effective solution, and we need to improve this treatment.
Entry
In recent years, there have been many mature solutions:
OGNL (http://www.ognl.org) and other settings, get the problem of the language of Java Object Properties solved the problem of the UI system such as the browser with the core business module interaction effect, and many front-end controllers (Front Controller It is good to achieve OGNL, such as webwork2, etc .; Hibernate (http://www.hibernate.org) O / R Mapping has solved uncoordinated from an object system to the relational database.
As a result, in the development, we don't have to be forced to convert between different JavaBeans when crossing the logical level.
achieve
Establish a detailed and meticulous business model, such as: EMPLOYEE
Package info.powersoft.sample;
Import java.util.date;
/ **
*
description: p>
*
Copyright: Copyright (c) 2005 p>
* @Author Guangzong.xu
* @since
2005-3-17
* @version 1.0
* /
/ **
* @Author Guangzong.xu
*
* Todo to change the template for this generated Type Comment Go To * Window - Preferences - Java - Code Style - Code Templates
* /
PUBLIC CLASS EMPLOYEEEE {
Private long id;
PRIVATE STRING NAME;
PRIVATE DATE DATEOFBIRTH;
PRIVATE DEPARTMENT
/ **
* @Return Returns the dateofbirth.
* /
Public Date getDateOfbirth () {
Return DateOfbirth;
}
/ **
* @Param DateOfbirth The dateofbirth to set.
* /
Public void setdateOfbirth (date dateofbirth) {
THIS.DATEOFBIRTH = DATEOFBIRTH;
}
/ **
* @Return Returns the department.
* /
Public department getDepartment () {
Return Department;
}
/ **
* @Param Department The Department To Set.
* /
Public void setDepartment (department department) {
THIS.DEPARTMENT = Department;
}
/ **
* @Return Returns the ID.
* /
Public long getId () {
Return ID;
}
/ **
* @Param id the ID to set.
* /
Public void setid (long id) {
THIS.ID = ID;
}
/ **
* @Return Returns the Name.
* /
Public string getname () {
Return Name;
}
/ **
* @Param Name the name to set.
* /
Public void setname (String name) {
THIS.NAME = Name;
}
}
Department
Package info.powersoft.sample;
/ **
*
description: p>
*
Copyright: Copyright (c) 2005 p>
* @Author Guangzong.xu
* @since
2005-3-17
* @version 1.0
* /
/ **
* @Author Guangzong.xu
*
* Todo to change the Template for this generated Type Comment Go To to
* WINDOW - Preferences - Java - Code Style - Code Templates
* /
Public class divance {
Private long id;
PRIVATE STRING NAME;
Private Department SuperDepartment;
/ **
* @Return Returns the ID.
* /
Public long getId () {
Return ID;
}
/ **
* @Param id the ID to set.
* /
Public void setid (long id) {this.id = ID;
}
/ **
* @Return Returns the Name.
* /
Public string getname () {
Return Name;
}
/ **
* @Param Name the name to set.
* /
Public void setname (String name) {
THIS.NAME = Name;
}
/ **
* @Return Returns The SuperDepartment.
* /
Public department getsuperDepartment () {
Return SuperDepartment;
}
/ **
* @Param SuperDepartment The SuperDepartment To Set.
* /
Public void setsuperDepartment (department superDepartment) {
THIS.SUPERDEPARTMENT = SuperDepartment;
}
}
DAO
Package info.powersoft.sample;
/ **
*
description: p>
*
Copyright: Copyright (c) 2005 p>
* @Author Guangzong.xu
* @since
2005-3-17
* @version 1.0
* /
/ **
* @Author Guangzong.xu
*
* Todo to change the Template for this generated Type Comment Go To to
* WINDOW - Preferences - Java - Code Style - Code Templates
* /
Public interface Employeedao {
Long InsertemPloyee (EMPLOYEE EMPLOYEE);
}
Use WebWork2 as a Front Controller, and set the service model as a variable in the corresponding action, set the corresponding getter, setter, such as
Package info.powersoft.sample;
/ **
*
description: p>
*
Copyright: Copyright (c) 2005 p>
* @Author Guangzong.xu
* @since
2005-3-17
* @version 1.0
* /
/ **
* @Author Guangzong.xu
*
* Todo to change the Template for this generated Type Comment Go To to
* WINDOW - Preferences - Java - Code Style - Code Templates
* /
Public class employeaction {
Private Employeedao Employeedao;
PRIVATE EMPLOYEE EMPLOYEE
/ **
* @Return Returns the Employeedao.
* /
Public employeedao geteMPloyeedao () {
Return Employeedao;
}
/ **
* @Param Employeedao the Employeedao to set.
* /
Public void setEmployeedao (Employeedao Employeedao) {this.employeedao = Employeeda
}
/ **
* @Return Returns the Employee.
* /
Public Employee getEmployee () {
Return Employee;
}
/ **
* @Param Employee The Employee To Set.
* /
Public void setemployee (Employe Employee) {
this.employee = Employee;
}
Public String Execute () throws exception {
Employeedao.insertemployee (Employee);
Return "Success";
}
}
Where EMPLOYEDAO is DAO for stored domain objects into the database, and specific implementations can be used by Hibernate. This is familiar, not here.
The page sent to the browser is
hEAD>