Project practice bits

xiaoxiao2021-03-06  46

1) First HTML again JSPWeb Application is a collection of HTML for customers, making an HTML sample to make customers early adjustment needs, and easy to use HTML Struts to transform

2) Reusable Design can write a lot of common features that have the status of the current project, which is responsible for design implementation and maintenance by the master. Such a module can find a lot, such as internal search (in line-containing SQL Search Engine Recounted), role resource permission system

3) Don't Reinvent The Wheeljarkata Commons project has many excellent practical JAR, from the famous Digester, BeanUtils, DBCP, Collectes to Codec, IO, NET, FileUpload, HttpClient can use too much resources, and learn very well

4) Explicit and score-level exception declaration If a method may throw DaOException, NodataFoundException, APPEXCEPTION, UNEXPECTEDEXCE, then you need to list all the way you cannot declare directly to write through Exception {...} In addition, I think J2EE project, Each level needs to define two layers of Exception (logically, not necessarily), one layer is internal to use, interact with the upper and lower layers, such as java.rmi.RemoteException is a higher level of exception, all detail levels In this layer, you should use the Exception's initcause () method package and then thrown.

The above levels are not required, but in most cases, a complete Exception system needs to be created. If necessary, the program can pass through Catch APPEXCEPTION to completely avoid these foreseeable exceptions, of course, the corresponding UNEXPECTEDEXCEPTION will certainly do not need Application processing. Common ApplicationException has InvalidParameterException, DaoException, NodataFoundException, ToolargeResultseTexception, OptImisticLockingException, and more. For convenience of managing and use (need for front end error), each Exception is preferably an ID and a String type Field to illustrate the true error cause

5) Value Object, Data Transfer Object) The role of I understanding Vo / DTO is not to simplify the program, falling in reducing coupling. In fact, some vo's use is very annoying, it will only be embodied when the interface should be changed, so that one person does not need to read another code and can be changed according to VO / DTO. My current project Vo is mainly used between Action <-> EJB, in general, there is no big problem. I don't know how to apply Hibernate, but currently in our iBatis practice, I have added VO for the main Entity, let iBatis will directly map the results of the database into the VO Entity and return, not small

6) The transaction processing EJB container can manage the transaction itself, then each EJB Call will be a transaction, this feature is attractive. Below is a piece of EJB-JAR.XML AccountcodeMgr AccountcodeMgr com.medlog.business.Parasetting.accountcodemgrhome < / home> com.medlog.business.parasetting.accountcodemgr com.medlog.business.parasetting.accountcodeMgrejb stateless stateless stateless > Container When there is no EJB, use iBatis as an example, the following method can be implemented in basedao in Basection processing constructor () {SQLMAP = SQLMaputil.getInstance (). getSqlMap ();} startTransaction () {sqlMap.startTransaction ();} endTransaction () {sqlMap.commitTransaction (); sqlMap.endTransaction ();} rollbackTransaction () {sqlMap.endTransaction ();} like the rest of the process .

7) Fast Lane Reader Pattern for Dao Diplomatic Fast Channel ?? EJB initialization, JNDI Finding, and transaction management come with an additional overhead, so when you only browse at the front, we applied Fast Lane when you need to change the content of the database. Reader mode, Action saves business delegate processing, and BizDelegate makes judgments according to whether it is changed, if the answer is affirmative, it will give the request to EJB processing, but if only view, BizDelegate will wake up DAO to perform SELECT operations, Thereby bypassing the EJB layer acceleration speed

8) BusinessDelegate and EJB parameter check or because EJB has Overhead, often in the BizDelegate layer, one parameter check, if you have a fault to return to InvalidParameterException, do not waste EJB resources, but there is a possibility, EJB_A CALLED EJB_B WITH A Set of invalid INPUTS, such a situation allows the EJB layer to review the parameters, although it will be repeated, but this Overhead is inevitable.

9) Webkey Application Defines some common JSP ActionRequest / session attributename, which makes the program readability, because one request does not need to use more than 5 Attributes in most cases, so we can have: user_vo_key User_role_list save user information, MENU_ITEM_LIST memory menu item, Search_criteria_one (~ file) save search criteria, Search_Result_List_one (~ FIVE) save result, list_one (~ five) and Object_one (~ FIVE) save additional information. There is no doubt that the code readability is greatly improved, but I am still considering whether there is a better way, after all, Webkey still can't get rid of the junior programmer casually add / chaos to the Object to assign the nightmare 10) Optimistic Locking I am doing it now. The project also uses Optlocking's thoughts. Simply says, the first we assume that every user will view data before Update, or our web design makes Frontend every possible data change, there is a corresponding view. (select) operation. Based on this, we define if a data D is changed by another user B after user A, then user a next to the change request of D will be returned (with a special exception), and require A Replace the data and update. If this assumption and limited, you can have the following method to ensure that the update of the data is inherently entered into the <1> of each required table to add the Lastupdatedon domain <2> Each SELECT will select this field for this field UPDATE Join WHERE LASTUPDATEDON = # last LastUpdatedon when using <3> Update, if the user b has changed a data, he must also change Lastupdatedon so that user A uses where lastupdatedon = *** UPDATE that cannot be changed to any data. Frontend can also be reminded by JS according to this (UpdatedCount = 0)

- == Welcome everyone with the topic of this article and interested, I discuss issues == -

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

New Post(0)