spring入门(七) spring mvc+mybatis+generator

2021-05-18 12:30

阅读:516

标签:执行   dbcc   pass   pre   core   big   comm   打开   1.4   

1.Mybatis-Generator下载

地址:https://github.com/mybatis/generator/releases

我使用的是 mybatis-generator-core-1.3.7 

2.配置generatorConfig.xml

官网: http://www.mybatis.org/generator/configreference/xmlconfig.html

 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     
 7     classPathEntry    location="mysql-connector-java-5.1.4.jar"/>
 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:3306/test" userId="root" password="123456">
15         jdbcConnection>
16         javaTypeResolver>
17             property name="forceBigDecimals" value="false"/>
18         javaTypeResolver>
19         
20         javaModelGenerator targetPackage="com.ice.model" targetProject="d:\src">
21             property name="enableSubPackages" value="true"/>
22             property name="trimStrings" value="true"/>
23         javaModelGenerator>
24         
25         sqlMapGenerator targetPackage="com.ice.mapper" targetProject="d:\src">
26             property name="enableSubPackages" value="true"/>
27         sqlMapGenerator>
28         
29         javaClientGenerator type="XMLMAPPER" targetPackage="com.ice.dao" targetProject="d:\src">
30             property name="enableSubPackages" value="true"/>
31         javaClientGenerator>
32         
33         table tableName="customer" domainObjectName="Customer" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
34         table>
35     context>
36 generatorConfiguration>

3.根据以上的配置,准备数据库驱动 mysql-connector-java-5.1.4.jar

4.把 mybatis-generator-core-1.3.7 , generatorConfig.xml , mysql-connector-java-5.1.4.jar 放在一个文件夹 mybatis-generator

5.确定 d:\src 存在,不存在则自己手动创建一个.

6.执行命令

在mybatis-generator目录按住Shift键,右键鼠标选择"在此处打开命令窗口",执行

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

如果不写 -overwrite,那么生产的文件不会覆盖,而是产生新的版本.

比如,第一次执行,CustomerMapper.java

第二次执行,CustomerMapper.java.1,第三次执行 CustomerMapper.java.2

 

spring入门(七) spring mvc+mybatis+generator

标签:执行   dbcc   pass   pre   core   big   comm   打开   1.4   

原文地址:https://www.cnblogs.com/ICE_Inspire/p/9744721.html


评论


亲,登录后才可以留言!