Summary
For project developers, to speed up the development of the system, improve the maintainability and scalability of the system, the first task is to divide the hierarchy of the system, rationally design the representation logic, business processing logic and data logic. The MVC pattern is a good solution for the separation of presentation, control and business processing, this paper mainly introduces the design and implementation of the financial system under the struts framework.
Key Words
MVC pattern; Struts framework; Web application
TP391 Identification Code of the classification number of the figure A
Introduction
Many of the problems encountered in software development work may have been in the previous development of similar software in the process has also been resolved, the solution to the problem of the use of good methods, technology accumulated and constantly summed up to form a fixed solution, a model, In order to solve similar problems in the future system development process. Design pattern is a summary of previous development experience, it's proposed so that developers can be simple and convenient reuse of successful design programs, without having to do repetitive work every time.
The financial system has the complexity of the business logic involved, the need for flexibility, and even the individual business may be in the process of changing the characteristics of the system, so how to organize applications to make it easy to maintain and upgrade is the first issue for developers. Earlier application development was done in a procedural language, they mix data-tier code such as database query statements with presentation-layer code such as HTML, so that both changes to the business logic and changes to the interface display involve the whole of the application, making it difficult to maintain the program.
Web-Layer Solution--MVC mode
The proposed MVC pattern solves the above problem completely. MVC is the abbreviation for model (models)--view (--controller), which is suitable for the development of large, scalable Web applications, which forcibly separates the input, processing, and output of the application into three core parts of the model, view, and controller. They perform different tasks, and any part of the modification does not affect the other two parts.
In the MVC pattern, the model encapsulates the core data, logical relation and business rules of the application problem, and provides the process of business logic. The model is called by the controller to complete the process of problem-handling, on the other hand, to obtain display data for the view provides the operation of accessing the data. Because models are not data-format-independent, a model can provide data for multiple views, so that a model can be reused by multiple views at a time, thus avoiding duplication of code.
A view is an interface that users see and interact with in the MVC pattern. The view obtains data from the model, and the view's update is controlled by the controller. The view does not contain the processing of any business logic, it is just a way of outputting data.
In the MVC pattern, the controller mainly plays the role of navigation, it calls the corresponding model and view according to the user's input to complete the user's request. The controller itself does not output anything, it accepts the user's request and decides which model artifacts to call and which view to display the data returned after the model is processed.
The process of MVC is this: For each user input request, first by the controller to receive, and decide which model to process, and then the model through business processing logic processing the user's request and return data, the last controller with the corresponding view format model returned data, and through the display page presented to the user. Figure 1 shows the respective functions of the model, view, controller, and the interrelationships between the three modules:
Figure 1
struts is the framework for implementing the MVC pattern
Design pattern is the summary of software development experience, it is a concept, is a logical entity, and the framework can be regarded as a specific platform based on one or several design patterns of physical implementation. Design patterns are more abstract than frames, the design pattern can only be represented as code, and the framework itself is represented by code, and the framework is a design-specific class with different functions and links between classes and classes, creating a reusable, scalable solution to a particular type of problem.
Struts is a common framework for implementing the MVC pattern, consisting of four major components, models, views, controllers, and XML files. The model is typically implemented by a Java bean or EJB component, which handles business logic; The view includes a set of JSP files, which are mainly made up of JSP tags or custom tags, which simplifies the coding of JSP pages; in the Struts framework, the controller mainly includes the action The Servlet class and action class, the action servlet, is the core part of struts, which accepts a user's HTTP request, forwards the request to the appropriate action object based on the configuration information, and the action class is responsible for invoking the model's methods and helping to control the process of the application Struts includes the Web.xml and Struts-config.xml two profiles, where Web.xml is a publishing profile for Web applications, and Struts-config.xml is a description of the special information configuration associated with Struts.
The design and implementation of the financial system under the framework of Struts
The entire project consists of the financial system, logistics system and customer management system three parts, due to the financial settlement business and procurement, warehousing and sales and other logistics links exist a certain degree of connection, therefore, the realization of financial system functions and maintenance convenience or not for the whole project success and failure plays an important role.
The financial system mainly includes the settlement related business processing, such as supplier settlement, customer settlement, rebate processing, various books of the query, Account table maintenance and so on. The following is an example of customer settlement to illustrate the design and implementation of the system under the struts framework.
After the user selects the Customer Checkout submenu, enter the Customer settlement page, where the customer name, the sales order code, the payment method for the fee, and the detailed collection information are filled in. The customer name and the sales order code support the Fuzzy inquiry function; The payment method includes three kinds of cash, bank and pre-payments, which can be selected for input; The detailed collection information includes the salesman's name or code, the total settlement amount, and the login account book. All the above information is completed, you can click to submit, if the information completed in line with the settlement conditions, then after the business processing logic processing, the system to the user to display the statement sheet page, if the submission is unsuccessful, then display the error message. The forwarding relationship of information between Web Components is shown in Figure 2
Figure 2
Ctmbform as a actionform bean, you can pass an HTML form between the view and the controller, its properties correspond to the fields in the form, and the Ctmbform Validate () method completes the validation check related to the form's data format and syntax. such as sales order encoding, settlement amount can not be empty.
The Actionservlet doget () or Dopost () method of the Struts framework's core controller component calls its process () method to process the request after it receives a user request. First select the child application module capable of handling the current request, write configuration information and message resources in the request scope, then complete some preprocessing request operations, create and save the Ctmbaction instance at the end of the preprocessing request operation, and invoke the Ctmbaction instance's execute ( Method, the method calls the corresponding model for the actual business logic processing, completes the user's request, and finally executes the request forwarding or redirection according to the result returned by the Execute () method.
In the system, the model is implemented by EJB component, and the multilayer structure of the system is designed as shown in Figure 3:
Figure 3
CTMBEJB is run in an EJB container as a jndi resource, ctmbejbdelegateimpl the business broker implementation class in a multi-tier structure cannot create CTMBEJB components, but instead obtains a reference to the resource by looking for a Jndi resource named "EJB/CTMBEJB".
The role of the ICTMB interface is to weaken the relationship between the client program and the model, through which the client program accesses the business method of the EJB component.
Ctmbaction the sequence diagram of a call to an EJB component is shown in Figure 4:
Figure 4
In the multi-layer structure, the business object Bo mainly encapsulates some entities, such as customer Customerbo, sales order Salesslipbo, settlement sheet Balancingslipbo, account receivable Accountsreceivablebo, Pre-billing Prereceivingbo, Cash Account CASHACCOUNTBO and bank account BANKACCOUNTBO etc. Figure 5 shows the correlation between the seven business objects mentioned above, as well as the properties and methods of some business objects:
Figure 5
A data Access object, or DAO, is a design pattern that implements the persistence framework, and its introduction can weaken the connection between business processing logic and database access, which translates the processing of business object Bo into operations on the database, On the other hand, you can map the results of the query database to the business object Bo. DAO provides interfaces to the operation of relational databases, such as creating databases, defining tables, indexes, adding, deleting, modifying, and querying tables. The system chooses the OJB software, it is a kind of persistence frame that implements with DAO design pattern.
Concluding remarks
Struts provides a framework for Web application development, and the JSP page does not contain any business logic, and the controller component Actionservlet can be provided using the struts framework, and developers need to focus most of their effort on the processing of the actual business logic, This facilitates the rapid and efficient development of web applications. In the struts framework, the user display, control logic and business processing logic are separated, if the business requirements change, the main modification is used to deal with the business logic EJB or JavaBean component, so it is easy to maintain and upgrade the system. In summary, the struts framework is suitable for the development of scalable, large Web applications.