Automatically create code--SSM framework using MyBatis generator __mybatis

Source: Internet
Author: User

MyBatis belongs to a semi-automatic ORM framework, the main task is to configure the mapping mapping file, but the handwriting mapping file is prone to error, so you can use the MyBatis generator to automatically generate entity classes, DAO interfaces and mapping mapping files. This saves a lot of effort by copying the generated code into the Project project.

There are many ways to use automatic generation, the following is very convenient and quick, do not need plug-ins, just download a few jar packages can be placed in a folder.

For example, my folder is on the desktop, the folder contains the required jar packages, including the MyBatis framework package, the database driver package, the MyBatis generator package


One of the generatorconfig is that we need to configure the file, configured as follows

<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis generator Configuration" "1.0//en Batis.org/dtd/mybatis-generator-config_1_0.dtd "> <generatorConfiguration> <!--database driver--> ; Classpathentry location= "Mysql-connector-java-5.1.38-bin.jar"/> <context id= "DB2Tables" my    
            Batis3 "> <commentGenerator> <property name=" Suppressdate "value=" true "/> <!--whether to remove automatically generated comments true: false: No--> <property name= "suppressallcomments" value= "true" /> </commentGenerator> <!--database link URL, user name, password--> <jdbcconnection drive rclass= "Com.mysql.jdbc.Driver" connectionurl= "Jdbc:mysql://localhost:3306/ceshi" userid= "root" password= "root" > </jdbcConnection> <javaTypeResolver> <properTy name= "Forcebigdecimals" value= "false"/> </javaTypeResolver> <!--generate the package name and location of the model--> <javamodelgenerator targetpackage= "Com.ssm.domain" targetproject= "src" > <property name = "Enablesubpackages" value= "true"/> <property name= "trimstrings" value= "true"/> </ Javamodelgenerator> <!--generate the package name and location of the mapping file--> <sqlmapgenerator targetpackage= "Com.ssm.mappi ng "targetproject=" src "> <property name=" enablesubpackages "value=" true "/> </sqlma Pgenerator> <!--generate the package name and location of DAO--> <javaclientgenerator type= "Xmlmapper" targetpackage= "C" Om.ssm.dao "targetproject=" src "> <property name=" enablesubpackages "value=" true "/> &L T;/javaclientgenerator> <!--the table TableName to be generated is the name of the table or view in the database Domainobjectname is the entity class name--> <tab Le tablename= "book" DomaInobjectname= "book" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" Enableselectbyexample= "false" Selectbyexamplequeryid= "false" ></table> </context> </generatorco Nfiguration>
In these jar packages, the file is located in the directory open cmd, execute the script

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

Then, under the SRC folder, you see the three folders (entity classes, interfaces, configuration files) that are configured in the configuration file.


Note: mybatis-generator-core-1.3.2 try not to put in the Chinese directory, in the noon directory generated code may be wrong.

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.