Mybatis Generator Usage
I. First, install the eclipse plug
Help - EclipserMarketplace find: Mybatis Generator 1.3.6 installed
Second, the official website to download Mybatis Generator tool
Official website address: https://github.com/mybatis/generator/releases , downloaded into the ring portion below:
After downloading extract the good, and copy features and plugins called good at extracting file to install these two files to the root directory of eclipse
Third, the new project
New - other-- look as follows
Click on the Next , you choose where you want the file to generate item names
Click to finish off. GeneratorConfig.xml file will be generated in springmvcfirst1208 project.
Note: springmvcfirst1208 database-related projects have to be generated jar package and the package mapper / pojo, because one would have to be configured in the configuration file.
Fourth, configure generatorConfig.xml
<?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>
<!-- targetRuntime:此属性用于指定生成的代码的运行时环境, MyBatis3是默认值 -->
<!-- id="context1"此处的id用context1也是默认值 -->
<context id="context1" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="false" />
</commentGenerator>
<!-- connectionURL:数据库的地址;driverClass:驱动类 -->
<jdbcConnection connectionURL="jdbc:mysql://localhost:3306/mybatis"
driverClass="com.mysql.jdbc.Driver" password="123456" userId="root" />
<!-- targetPackage是目标包名, targetProject是包所在的位置 -->
<javaModelGenerator targetPackage="com.itcast.ssm.po"
targetProject="mybatisNX/src" />
<!-- targetPackage放置生成的SQL映射文件, targetProject指定生成SQL映射的目标项目 -->
<sqlMapGenerator targetPackage="com.itcast.ssm.mapper"
targetProject="mybatisNX/src" />
<!-- targetPackage是目标包名, targetProject是包所在的位置;type:XMLMAPPER生成的对象是 MyBatis3.x
映射器基础结构的 Java接口 -->
<javaClientGenerator targetPackage="com.itcast.ssm.mapper"
targetProject="mybatisNX/src" type="XMLMAPPER" />
<!-- 数据库里的表名 -->
<table tableName="items"></table>
<table tableName="orders"></table>
<table tableName="orderdetail"></table>
<table tableName="user"></table>
</context>
</generatorConfiguration>
Note: In the configuration generatorConfig.xml before if built two packages in your project, in the above configuration, must pay attention to your name is written on the package; if not build a package, then the top of the configuration file you write What is the package name he will help you build a package package name of what. At the same time, but also to build the database, table built.
Fifth, the automatic generation of mapper.java and other documents mapper.xml
After that, you can see the files generated in the package
In this there may be omissions, please correct me a lot. If you feel it click okay to look at, it will be released about the IT industry in terms of follow-up.