[Original] Struts development in the middle of the middle

xiaoxiao2021-03-06  64

The Struts uses the MVC architecture framework to separate the View to the Model to give web application development with new connotations. However, after using Struts technology, the number of files large and small has surged. Bringing a small challenge to management and maintenance. On the one hand, we must enjoy the development efficiency of Struts, and on the other hand, it is also easy to maintain.

In Struts, there are two prominent keywords: structures and hierarchies. Be sure: the structure is rigorous, and the level is clear. If you can't catch these two points, your development must be very failed.

Although the number of files large and small, each document has a duty, it is never possible. Don't deliberately care about the number of files (because this is just a surface phenomenon), and it is necessary to focus on whether the structure is reasonable, whether the hierarchy is clear. If you learn to change your thinking, you will find that the number of files is a cost that uses Struts technology must pay; and if you have a work in the structure and hierarchy, this disadvantage is not a shortcoming.

So how should I go to work in the structure and level? The author of the rookie is currently thinking about two kinds of food:

(1) Division:

Place the same type of file that serves the same function in the same subdirectory. Each subdirectory represents a function; reduces cross access between different directories. In the subdirectories, there is also a subdirectory to form a multi-layer directory structure. NewArticleAction.java can be placed in a package called Articles.Newarticle in a package called Articles.NEWAVA, separated from other Java class. All JSP files associated with these two Java classes can be put on / web-inf / articles / newarticle / below.

(B), unified form: In the above two examples of java classes: real name: virtual name in the struts-config.xml: newArticleAction.java new_article_actionnewArticleForm.java new_article_formnew-article-forward.jsp new_article_forwardnew-article-main. JSP new_article_mainnew-article-message.jsp new_article_message At a glance Also, if there are multiple functions similar Java classes, these classes should also be consistent as much as possible. If the internal structure of NewArticleAction.java is like this:

Public Class NewArticleAction Extends Action {Public ActionForward Extende (ActionMapping Mapping, Actionform Form, HttpservletRequest Request, httpservletResponse response) throws Exception {...}

Protected Boolean ExecuteQuery (statement stmt, actionform form, httpservletRequest request) {......

Protected Boolean ExecuteUpdate (statement stmt, actionform form, httpservletRequest request) {...}}

Then the functionality similar newfoldertin.java, repairfoldersaction.java, ManageLinkSaction.java should also have ExecuteQuery (), ExecuteUpdate () method, the return value of these methods should be the Boolean type, the parameter type and number should also be the same. In this way, I understand NewArticleAction.java, which is equal to NewFoldertin.java, RepairFoldersAction.java, ManagelinkSaction.java, even if the number of Action classes is prolonged, can also be controlled. This is actually a deformation of the Java "package" concept, namely: unified entrance, unified export, wrap the specific implementation process in the "dark box". The author believes that the unity of form is an optimized structure, an important part of the hierarchy, and there are many techniques worth studying.

转载请注明原文地址:https://www.9cbs.com/read-117163.html

New Post(0)