Detailed description of the Automatic code generation engine in easyjweb tools

Source: Internet
Author: User

After the launch of the EasyJWeb-0.6.0, many netizens are very interested in the part of the code generation, I also asked a lot of questions about how to use easyjwebtools, how to support multi-Table Generation, page generation customization, and business logic customization. Next, I will give a brief introduction to the application methods and prospects of code generation in easyjweb tools.

1. Quick experience

Easyjweb has many beginners in Java in China, so the code writing and publishing methods are simple and clear, so that new users can get started quickly. In version 0.6.0, Ant and Maven are used to manage project releases, and some functions of the code generation engine are initially implemented. After you download the source code of the easyjweb project, it takes less than two minutes to implement a process of adding, deleting, modifying, querying, and paging Java Web code generation, compilation, packaging, and publishing. The entire process only requiresDownload easyjweb source code-> Create a table-> modify the data source configuration file-> execute the generated command easyjwebtools-> and then runYou can. The detailed steps are as follows:
  1. download the latest easyjweb version.
Http://www.easyjf.com/easyjweb/download.htm
  2. Create a database and a data table
Use the My SQL or ms SQL database to create a database and a table, such as message board ). Because the easyjweb tools business engine uses an ORM system to access the database, each table is required to set a primary key field named CID and of the type varchar (16, then there are other required fields. As shown in the following example table:
Create Table 'message '(
'Cid' varchar (16) not null,
'Title' varchar (100) not null,
'Inputuser' varchar (16) default null
'Inputtime' datetime default null,
Primary Key ('cid ')
) Engine = InnoDB default charset = utf8;

By default, easydbo, a lightweight ORM framework developed by easyjf, is used to access the database. Of course, you can choose other ORM systems, such as Hibernate and ibatis, based on your own situation.

  3. Modify the database access configuration file
The code generation engine in easyjweb tools currently generates code based on the field name of the data table. Therefore, to run the program correctly, you must ensure that the database connection configuration parameters are set correctly. We only need to modify the download source code in the src/main/easyjf-dbo.xml file. About easydbo configuration instructions, please see my "easydbo configuration file easyjf-dbo.xml detailed description" this article, address: http://www.easyjf.com/html/20060427/31970563-6771387.htm
  
  4. Run the easyjwebtools command
Enter cmd in the run bar of the Start Menu. Then run the CD command to switch to the bin directory of the easyjweb source code extraction directory.
Enter easyjwebtools <Table Name>
After you press any key, click any key on the keyboard. Until the Column Style of build successful is displayed. After the completion, go to the easyjweb decompression directory to generate the release Directory, which has a packaged easyjf-jweb-0.6.war file, copy the file to the Tomcat webapps directory. Start Tomcat.
  
Ii. Multi-Table Generation
In practical applications, we only have one table, but there are few. Moreover, it is impossible to create a war package every time a table is generated for addition, deletion, modification, and query. Isn't that funny?
In easyjweb tools, a single table is generated to provide a quick application experience. Therefore, the easyjwebtools Batch Processing Command combines the compilation, generation, re-compilation, packaging, and publishing processes. You can use the editor to open the easyjwebtools. Bar file in the bin directory, comment out (or delete) The call build. Bat compile and call build. Bat war lines in the file. In this way, only the code generation function is completed when easyjwebtools is executed, rather than the compilation and package release process.
To generate multiple tables, you only need to compile the source code of the easyjweb project. Then execute easyjwebtools again to generate the addition, deletion, modification, and query of each table, and then execute a re-compile and package and release command.
The entire process of operating on the command line is as follows:
Compile: Build compile
Repeat: easyjwebtools <Table 1>
Easyjwebtools <Table 2>
...
Easyjwebtoosl <Table n>
Finally, run the package and release: Build war

Iii. Outlook of the code generation engine
In actual projects, our applications are complex and there are many specific requirements during code generation, such:
1. We will involve hundreds of data tables.
2. These data tables also have various relationships, such as master-slave relationships, foreign key constraints, and associations. Many tables also support lazy load and other functions.
3. the operation does not simply add, delete, modify, and query, but also has more business logic.
4. When generating an ORM System Based on Hibernate, you must also generate related configuration files.
5. More options and interactive operations are required.
In addition, the Code Generation engine also needs to consider many issues, such as the maintainability of the page, the re-generation of the generated code when the demand changes, the scalability and maintainability of the generated code, and so on. The generation method, code style, page style, and so on all require the user to freely choose and customize the support.
Provides a visual user interaction interface, instead of a command line, which uses UML for modeling, generates table structures, generates relevant code, test code, and generates various page files based on the selected UML model, and package and release. Ideally, the code generation engine completes more than 70% of the repetitive coding tasks of a project. What programmers need to do is to make some personalized functional requirements or settings on the generated code or page.
Providing simple and fast J2EE application development solutions is the goal of easyjweb tools in the future. Easyjweb is an open-source project. Anyone who can speak Chinese can join us. We sincerely invite interested friends to join us in our efforts for easyjweb tools goals.

 

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.