Let's start our codesmith journey. Let's talk about the goals of this series of tutorials. As we all know, one of the powerful functions of codesmith is to generate batch code based on templates, this is why it attracts many programmers to use it. It greatly saves programming time and saves a lot of copy and paste waste operations.
First of all, since we want to explain how to use codesmith and powerdesigner to quickly generate batch code, of course we need to install the two software first. Let's briefly talk about how to install the two software, of course, cracking is only a learning purpose. Please do not use it for commercial purposes. You must support genuine products. Everyone is engaged in software and it is difficult to develop a set of software.
Codesmith Installation Method: 1). Click to download the Installation File 2). Run the installation procedure and choose the directory to be installed. The next step is OK.
3) run the command, select the codesmith installation directory, and click "Next" to crack
Now, you can start running the program -- codesmith professional 5.1 -- codesmith studio.
Powerdesigner installation method:Http://dev.firnow.com/course/3_program/java/javajs/20090908/174375.htmlcopy code
After the two software are installed, let's start using them. As before, we need to put forward the requirements and then use the instances, because we use them, it must be because they can cleverly solve a certain problem, or we will spend so much time and hard disk space to install them.
Well, our current requirement is: when receiving a new project, the programmer only needs to design the database structure (table, table field, the relationship between tables.One buttonTo immediately obtain allHierarchical Architecture code file. That is to say,We hope to get all the code we want without having to knock a line of code.! This is what the two software can do, and it is also our purpose to install them.
Now, the roles have been introduced. Let's see how they perform the wonderful performances:
First, we need to create a test database. For simplicity, we only need to create oneStudentTableAnd oneMajorTableThe table structure and relationship are as follows.
Let's see how to use powerdesigner to quickly create this database.
1. Start to use powerdesigner to create a database. First run the program and enter the main interface:
2. File-New Model-physical data model-physical dimo-- model nameSetTest, DBMS attribute is setMicrosoft SQL Server 2005:
3. Create a table template using the table tool:
4. Double-click a table template to set properties. First, SetMajorTable:
5. Set the table name and clickColumnsLabel, set field properties, set:
6. Because the majorid field is setAutomatic GrowthTo set its advanced attributes, select the majorid field, click Properties, and select the "Identity" check box on the General Panel:
7. After confirming, create another student table and set the fields:
8. create a foreign key majorid for student. You can use powerdesigner to easily complete this task. Select the link setting tool, hold down the left button on the student table, and drag it to the major table, you can add a foreign key of majorid to the student table:
9. Haha, now that the test table has been set up, set the database we want to generate. All these tables will be created in the database. We will go to the blank area of the design panel.Right-click-PropertiesIn the pop-up attribute Settings dialog box, set as follows:
10. Here we have completed the settings for the new database, but it is still blank in SQL. How can we port the structure designed here to sqlserver 2005? Perform the following operations:Database-generate Database, Set the export directory and file name for the stored procedure, and click OK:
11. Go to your export directory and you will see the exported database creation and storage process. Open the SQL statement and execute it. Then you will see that the database has been created magically:
12. Now, the database preparation is complete. In the next article, we will use the database and codesmith to automatically generate code in batches ~
Source code generated in the above practices:
SQL. SQL
/* ===================================================== =======================================* // * Database Name: pd_test * // * DBMS name: Microsoft SQL Server 2005 * // * created on: 2010/6/13 Sunday 17:27:17 * // * ================================== ===========================*/drop database pd_testgo/* ==== ========================================================== ===========================* // * database: pd_test * // * = ===========================*/create database pd_testgouse pd_testgo/* ==== ========================================================== =========================* // * Table: major * // * ============================================= ======================= */create table major (majorid int identity, name nvarchar (20) not null, remark nvarchar (max) null, constraint pk_major primary key (majorid )) go/* = =========================================* // * Table: student * // * ============================================= =========================*/create table student (studentid nvarchar (20) not null, majorid int null, name nvarchar (20) not null, sex bit not null, age int null, remark nvarchar (max) null, constraint pk_student primary key (studentid )) goalter table student add constraint fk_student_reference_major foreign key (majorid) References major (majorid) Go