The existing value of the Code Generator is selected from the blog of mechiland.

Source: Internet
Author: User

When I used ASP many years ago, I heard thatCodeThe magic of the generator. You only need to specify the database link. This code generator can generate an interface, select the data table you want to generate, and click the button, the addition, deletion, modification, and query interface based on the table and the corresponding ASPProgramThe code is generated, which is really convenient. At that time, I was familiar with ASP. After taking a look at this tool, I evaluated it and used it ...... See the ASP program generated by this toolSource codeIt is a bit unacceptable-case insensitive, large-section and large-section redundant code. Although the generated code can indeed complete specific business operations, the maintainability is indeed too bad. It is said that some high-quality code generators can generate better programs later, but since then, code generators have become synonymous with spam code. I would rather write a line of code by myself than use a code generator.

Now, when you focus on an industry or a specific business, you will find that the repeatability is so large. -- User management is similar in most places, but the user's relative fields are somewhat different. The user logon interface and logout interface may also be the same, but some images can be changed; most of the business operations are added, deleted, modified, and queried. This type of operation is constantly repeated in the same way and requires careful error. The permission management interface does not look very different ...... Maybe we have long been bored. The framework guarantees the quality of the project to some extent, but does not reduce the amount of coding; Some frameworks even require more coding (and learning time ). For example, compared with Servlet + JSP, struts in addition to JSP, also need to write a specific form, action, and add a few lines in the struts-config.xml; tapestry needs to write. page ,. HTML, the corresponding page class, if you need to verify, you have to write the delegate class; as for freemaker, the interface workload such as velocity may be smaller, but you have to write your own simple framework to implement the MVC mode. Spring integrates these presentation layers and looks better ......

The fundamental problem of the above solution is that the framework only guarantees the quality and maintainability of the project, but does not reduce the coding workload. Therefore, the use of code generators is taken for granted. There is already a precedent for this. The most effective and powerful code generation is the XDoclet EJB task. We know that to create an EJB, we need to create four other boring interfaces at the same time. In this regard, XDoclet can exert the power of code generation to the extreme. In addition, middlegen can also create Web applications based on databases and using hibernate, struts, and EJB technologies. It can generate JSP, Hibernate ing files, Java classes, and EJB classes. Middlegen should be the prototype of the most complete Application Generator I have seen, but it is not specific enough to shorten the coding time.

After several days of thinking about openbugz and the company's projects, I came up with this model:

Infrastructure: spring, hibernate, and tapestry

The advantages of spring and Hibernate are self-explanatory. Struts or webwork is not used in the front-end because the first two are not flexible enough in the interface representation. struts needs to work with tiles to Achieve flexible layout and webwork is not familiar with it, I don't know how to implement flexible layout. However, the layout problem in tapestry is almost no problem.

Application Technology: ant, XDoclet, freemaker, JUnit

Using freemaker instead of velocity is because the former has more support, and from the perspective of my usage, freemaker is relatively powerful.

Development steps:

1. First, the developer (project manager or technical manager) models the entire system as needed, completes the basic class diagram, and generates all business model classes;

2. Compile the hibernate ing file based on the business model class (XDoclet may be inconvenient to use, especially when the business model class has an inheritance relationship );

3 (Code Generation) generate the corresponding Dao interface, such as xxxdao, to add, delete, modify, and query XXX objects (this step can be omitted if spring hibernate template is used)

4 (Code Generation) generate the DAO implementation using hibernate

5 (Code Generation) generate the business logic layer code xxxmanager, which is used to call the DaO layer for various business logic operations;

6 (Code Generation) generate unit tests corresponding to xxxmanager

7 (Code Generation) generate the add, delete, modify, and query interface of the business model class HTML (through the template)

8 (Code Generation) The. page file required by the tapestry corresponding to the interface

9 (Code Generation) If verification is required, the required delegate class must also be generated.

10 (Code Generation) generate the corresponding add, delete, modify, and query page class

11 (code configuration) Configure Dao transactions in the spring configuration file

12 (code configuration) Configure xxxmanager in the spring configuration file

13 configure the database link and use schemaexport of Hibernate to directly generate the database

14. Generate the file structure of the entire project, including build. xml. If necessary, you can also generate a JBuilder or Eclipse project

15 Development: Modify xxxmanager and modify the interface.

From the above we can see that the workload of the entire project is already very low;-) This requires a relatively high requirement on business analysts, requiring a thorough analysis at a time. The last job in the project is to modify the business logic and modify the page. This is the power of the code generator.


Author's blog:Http://blog.csdn.net/mechiland/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.