About using mybatis Generator to automatically generate code, mybatisgenerator
1. Install the mybatis plug-in:
In eclipse, click help --> Install New Software... --> Add --> local to select the eclipse directory in the plug-in ---> updatesizefile (for details about the plug-in package, see mybatis-generator-master.rar)
Http://download.csdn.net/detail/u010489036/8593745
2. Create generatorConfig. xml:
Right-click the project --> New ---> Other --> mybatis plug-in, and click Next to generate the generatorConfig. xml file.
3. Configure the generatorConfig. xml file (the simplest way to create a DB2 database is used here)
<? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE generatorConfiguration PUBLIC "-// mybatis.org//DTD MyBatis Generator Configuration 1.0 //" http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd "> <generatorConfiguration> <context id =" context1 "> <jdbcConnection driverClass =" com. ibm. db2.jcc. DB2Driver "connectionURL =" jdbc: db2: // ip: port/Database Name "userId =" userid "password =" password "/> <javaModelGenerator targetPackage =" com. dao. ibatis. model "t ArgetProject = "project name/src/dao"/> <sqlMapGenerator targetPackage = "com. dao. ibatis. mapper "targetProject =" project name/src/dao "/> <javaClientGenerator targetPackage =" com. dao. ibatis. client "targetProject =" project name/src/dao "type =" XMLMAPPER "/> <! -- Table Name List multiple tables can be written here --> <table schema = "" tableName = "database indicates" domainObjectName = "PO Object Name"/> </context> </generatorConfiguration>Xml configuration file
4. Add the corresponding db2 driver jar package (db2jcc. jar), which needs to be added based on the actual database. Http://download.csdn.net/detail/u010489036/8593783
5. Right-click the mybatis file and execute:
At this point, if the database connection is normal, the corresponding PO object will be created.
--- ===================================================== ======= --
I have encountered an exception in the project. Here, I would like to share with you:
I found a lot of information on the Internet and did not provide a clear description of this exception. At first I thought it was a configuration file problem. I tried to change the eclipse version, JDK version, and other methods, is determined because
The version of the db2 driver jar package downloaded from the internet is incorrect ).