1. Create a folder named myibatisgen.
2. Download The mybatis-generator-core-1.3.1.jar or other jar packages to the myibatisgen folder.
3. Create the configuration file "generatorconfig. xml" for the generated code"
4. generate code
Java-jar mybatis-generator-core-1.3.1.jar-configfile generatorconfig. XML-overwrite
5. complete code generation based on the above steps. Generatorconfig. xml configuration is the foundation of code generation, and a configuration file is attached for your reference.
<? 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> <! -- Database driver --> <classpathentry location = "ojdbc14.jar"/> <! -- Targetruntime: The runtime environment for generating code. Because I am using ibatis2, I chose ibatis2java5. --> <Context ID = "oracletables" targetruntime = "ibatis2java5"> <commentgenerator> <property name = "suppressdate" value = "true"/> </commentgenerator> <! -- Database Configuration --> <jdbcconnection driverclass = "oracle. JDBC. driver. oracledriver "connectionurl =" JDBC: oracle: thin: @ 192.168.3.222: 1521: orcl "userid =" orcl "Password =" orcl "> </jdbcconnection> <javatyperesolver> <property name =" forcebigdecimals "value =" false "/> </javatyperesolver> <! -- Model configuration --> <javamodelgenerator targetpackage = "com. test. model "targetproject =" test \ SRC "> <property name =" enablesubpackages "value =" true "/> <property name =" trimstrings "value =" true "/> </ javamodelgenerator> <! -- Dao configuration --> <sqlmapgenerator targetpackage = "com. test. dao "targetproject =" test \ SRC \ sqlmaps "> <property name =" enablesubpackages "value =" true "/> </sqlmapgenerator> <javaclientgenerator type =" Spring "targetpackage =" com. test. dao "targetproject =" test \ SRC "> <property name =" enablesubpackages "value =" true "/> </javaclientgenerator> <! -- Database table configuration domainobjectname: class name --> <Table tablename = "order_order" domainobjectname = "order"> <columnoverride column = "ID" property = "ID" javatype = "Java. lang. long "jdbctype =" numeric "/> </table> <Table tablename =" order_issue_level "domainobjectname =" issue_level "> <columnoverride column =" ID "property =" ID "javatype = "Java. lang. long "jdbctype =" numeric "/> </table> </context> </generatorconfiguration>
6. If you do not like the annotation information of the mybatis code generator with proxy in the generated code, you can configure the following configuration parameters to disable the generation of annotation information:
<Commentgenerator>
<Property name = "suppressallcomments" value = "true"/>
</Commentgenerator>
7. If you want to change the name of the example class generated by mybaits code generator, it is implemented through the plug-in. That is, the following plug-in configuration parameters are critical.
<Plugin type = "org. mybatis. generator. plugins. renameexampleclassplugin">
<Property name = "searchstring" value = "example $"/>
<Property name = "replacestring" value = "criteria"/>
</Plugin>
8. For specific configuration items, you can view the documents under the mybatis-generator-core-1.3.1/Doc.