MyBatis uses the---to automatically generate mapper, model, mapper.xml using the Mybatis-generator

Source: Internet
Author: User
Tags generator

Before today, just heard mybatis, useless, has been used ibatis, at that time feel very simple, today the project used the mybatis,example of things, just took over, dizzy for a long time. Only now has learned how to generate classes and configuration files:

1, I use is mybatis-generator-core-1.3.1, this version. Open inside there are lib in the Mybatis-generator-core-1.3.1.jar, the most important.

2. Open Generator.xml

<pre name= "code" class= "HTML" ><?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> <!--classpathentry: Database JDBC driver, switch to your own drive location--<classpathentry location= "<span style=" color: #ff6666; "
	
	>E:\spp\myeclipse_plugin\mybatis-generator-core-1.3.1\mysql-connector-java-5.1.7-bin.jar</span> "/> <context id= "Mysqltables" targetruntime= "MyBatis3" > <!--Remove automatically generated comments--<commentGenerator> < Property Name= "Suppressallcomments" value= "true"/> </commentGenerator> <!--database Connection configuration--<jdbcco Nnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "Jdbc:mysql://192.168.5.18:3306/zhyl" userid= "Zhyl" password= "Zhyl_pass" > </jdbcConnection> <!--and generate VO about-<javatyperesolver > <property n Ame= "ForcebigdeCimals "value=" false "/> </javaTypeResolver> <!--targetproject: automatically generated code location--<javamodelgenerat or targetpackage= "<span style=" color: #ff6666; " >com.peony.province.model</span> "targetproject=" <span style= "color: #ff6666;" >F:\hiscms\src</span> "> <property name=" enablesubpackages "value=" true "/> <property name=" trim Strings "value=" true "/> </javaModelGenerator> <sqlmapgenerator targetpackage=" <span style= "color:# ff6666; " >resources.mybatis.province</span> "targetproject=" <span style= "color: #ff6666;" >F:\hiscms\src</span> "> <property name=" enablesubpackages "value=" true "/> </sqlmapgenerator&
		Gt <javaclientgenerator type= "Xmlmapper" targetpackage= "<span style=" color: #ff6666; " >com.peony.province.mapper</span> "targetproject=" <span style= "color: #ff6666;"
	>F:\hiscms\src</span> "> <property name=" enablesubpackages "value=" true "/>	</javaClientGenerator> <!--tableName: A database table for automatic code generation; Domainobjectname: JavaBean class name that corresponds to a database table---<table Tablename= "<span style=" color: #ff6666; " >tb_province</span> "Domainobjectname=" <span style= "color: #ff6666;"
 >TbProvince</span> "/> </context> </generatorConfiguration>


</pre><p></p><pre>
The red part needs to be modified!!!

3. Run the jar package generation file

my: Java-jar E:\spp\myeclipse_plugin\mybatis-generator-core-1.3.1\lib\mybatis-generator-core-1.3.1.jar- ConfigFile E:\spp\myeclipse_plugin\mybatis-generator-core-1.3.1\generator.xml-overwrite

E:\spp\myeclipse_plugin\mybatis-generator-core-1.3.1\lib\mybatis-generator-core-1.3.1.jar---The path of the jar package

E:\spp\myeclipse_plugin\mybatis-generator-core-1.3.1\generator.xml absolute path to---configuration file


OK, the required files are generated.

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.