development tools

Mybatis is a semi-automatic ORM. In using this framework, the largest workload is to write mapping files for Mapping. Since manual writing is prone to errors, we can use Mybatis-Generator to automatically generate files for us.



1. Related documents The download

of Mybatis-Generator can go to this address: https://github.com/mybatis/generator/releases

Since I am using the Mysql database, I need to prepare a driver jar package to connect to the MySQL database. The

following is Screenshots of related files:





Like Hibernate reverse generation, a configuration file is also required here:

generatorConfig.xml

Copy code
Copy code
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE generatorConfiguration
3 PUBLIC " -//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
4 "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
5 <generatorConfiguration>
6 <!--Database Driver- ->
7 <classPathEntry location="
8     <context id="DB2Tables"    targetRuntime="MyBatis3">
9         <commentGenerator>
10             <property name="suppressDate" value="true"/>
11             <property name="suppressAllComments" value="true"/>
12         </commentGenerator>
13         <!--数据库链接地址账号密码-->
14         <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/mymessages" userId="root" password="root">
15         </jdbcConnection>
16         <javaTypeResolver>
17             <property name="forceBigDecimals" value="false"/> 19 <!--Generate Model class storage location-->
18 </javaTypeResolver>

20         <javaModelGenerator targetPackage="lcw.model" targetProject="src">
21             <property name="enableSubPackages" value="true"/>
22             <property name="trimStrings" value="true"/>
23         </javaModelGenerator>
24         <!--生成映射文件存放位置-->
25         <sqlMapGenerator targetPackage="lcw.mapping" targetProject="src">
26             <property name="enableSubPackages" value="true"/>
27         </sqlMapGenerator>
28         <!--生成Dao类存放位置-->
29         <javaClientGenerator type="XMLMAPPER" targetPackage="lcw.dao" targetProject="src">
30             <property name="enableSubPackages" value="true"/>
31         </javaClientGenerator>
32 <!--Generate corresponding table and class name-->
33 <table tableName="message" domainObjectName="Messgae" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId=" false"></table>
34 </context>
35 </generatorConfiguration>
Copy code
Copy code
I have marked the comments where the file configuration needs to be modified. The relevant paths here (such as database driver packages, generate corresponding related The file location can be customized) cannot contain Chinese.

In the above configuration file:

<table tableName="message" domainObjectName="Messgae" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="






java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite




2. How to use Hold down the Shift key

in this directory, right-click and select "Open command window here", copy and paste the generated statement file code.



Take a look at the renderings:



http://www.cnblogs.com/smileberry/p/4145872.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326225047&siteId=291194637