This article allows you to easily generate code for accessing the database through ibatis based on the database table.
1. Obtain
Http://ibatis.apache.org/abator.html
Ii. Unpack the package to the directory after downloading
D:/abator-0.6.5-124
/Abator. Jar
Abator-src.zip
3. Configuration File
Create a configuration file config. XML with the following content:
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype abatorconfiguration public
"-// Apache Software Foundation // DTD abator for ibatis configuration 1.0 // en"
Http://ibatis.apache.org/dtd/abator-config_1_0.dtd>
<Abatorconfiguration>
<Abatorcontext>
<! -- Todo: Add database connection information -->
<Jdbcconnection driverclass = "oracle. JDBC. oracledriver"
Connectionurl = "JDBC: oracle: thin: @ 172.17.1.103: 1521: ora18"
Userid = "test"
Password = "test">
<Classpathentry location = "D:/Setup/javalib/classes12.jar"/>
</Jdbcconnection>
<Javatyperesolver>
<Property name = "forcebigdecimals" value = "false"/>
</Javatyperesolver>
<Javamodelgenerator targetpackage = "test"
Targetproject = "/test">
<Property name = "enablesubpackages" value = "true"/>
<Property name = "trimstrings" value = "true"/>
</Javamodelgenerator>
<Sqlmapgenerator targetpackage = "test"
Targetproject = "/test">
<Property name = "enablesubpackages" value = "true"/>
</Sqlmapgenerator>
<Daogenerator type = "ibatis" targetpackage = "test"
Targetproject = "/test">
<Property name = "enablesubpackages" value = "true"/>
</Daogenerator>
<Table tablename = "t_area_code">
<Columnoverride column = "area_code" property = "area_code"> </columnoverride>
</Table>
</Abatorcontext>
</Abatorconfiguration>
Here is the Oracle-related configuration, and other databases can be like this. Among them, javamodelgenerator, sqlmapgenerator, and daogenerator are the relevant code that will be generated and can be added or deleted as needed, A more complete configuration file can look at the definition http://ibatis.apache.org/dtd/abator-config_1_0.dtd of DTD
4. Run (create a directory named test under the root directory of drive D and store the generated files)
Java-jar abator. Jar config. xml false
Java-jar abator. Jar config. xml true
Java-CP abator. Jar org. Apache. ibatis. abator. API. abatorrunner config. xml false
Java-CP abator. Jar org. Apache. ibatis. abator. API. abatorrunner config. xml true
The preceding four methods can be run. True/false indicates whether to overwrite the original code.
5. view and modify the generated file.
After running successfully, the following information is displayed:
Abator finshed successfully, there were warninig
Now, you can manually modify the generated code.