Mybatis-generator generates model and Dao Layer Code

Source: Internet
Author: User

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.

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.