MyBatis automatically generate Java code

Source: Internet
Author: User

The SSM framework does not have a db+record pattern and is particularly laborious to write, and can only be done with the following methods.

, *.jar is downloaded, SRC is a new blank directory, and. XML is configured as follows.

<?XML version= "1.0" encoding= "UTF-8"?>    <!DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en" "/http Mybatis.org/dtd/mybatis-generator-config_1_0.dtd ">    <generatorconfiguration>    <!--Database-driven -    <Classpathentry Location= "Mysql-connector-java-5.1.22-bin.jar"/>        <ContextID= "Db2tables"Targetruntime= "MyBatis3">            <Commentgenerator>                < Propertyname= "Suppressdate"value= "true"/>                  <!--whether to remove automatically generated comments true: Yes: false: No -            < Propertyname= "Suppressallcomments"value= "true"/>            </Commentgenerator>              <!---Database link URL, user name, password -        <jdbcconnectionDriverclass= "Com.mysql.jdbc.Driver"Connectionurl= "Jdbc:mysql://127.0.0.1/yanan?characterencoding=utf8"userId= "Yanan"Password= "1234">          </jdbcconnection>            <Javatyperesolver>                < Propertyname= "Forcebigdecimals"value= "false"/>            </Javatyperesolver>            <!--generate the package name and location of the model and create a new SRC folder where the current file is stored -        <JavamodelgeneratorTargetpackage= "Test"Targetproject= "src">                < Propertyname= "Enablesubpackages"value= "true"/>                < Propertyname= "Trimstrings"value= "true"/>            </Javamodelgenerator>            <!--Build the package name and location of the mapping file -        <SqlmapgeneratorTargetpackage= "Test"Targetproject= "src">                < Propertyname= "Enablesubpackages"value= "true"/>            </Sqlmapgenerator>            <!--generate DAO's package name and location -        <Javaclientgeneratortype= "Xmlmapper"Targetpackage= "Test"Targetproject= "src">                < Propertyname= "Enablesubpackages"value= "true"/>            </Javaclientgenerator>            <!--the table to be generated tablename is the name of the table or view in the database Domainobjectname is the entity class name. Only one table can be generated from a table -        <TableTableName= "User"Domainobjectname= "User"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"></Table>        </Context>    </generatorconfiguration>    
View Code

In the current directory, open a command window and type the following command:

Java-jar Mybatis-generator-core-1.3.5.jar-configfile Generatorconfig.xml-overwrite

As you can see, the corresponding entity classes, mapping files, and entity class interfaces are generated under the corresponding directory of the SRC configuration. That's it.

Be careful not to listen to what is said on the Internet to find bin. Only one can be generated at a time. Ensure that the above files (tools) are in the same directory, any directory. On the configuration file, join the port

MyBatis automatically generate Java code

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.