mybatis 把數據庫里面的表自動生成實體類跟mapper的方法


 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 
 6 <generatorConfiguration>
 7 
 8     <!--指定特定數據庫的jdbc驅動jar包的位置 -->
 9     <classPathEntry
10             location="G:\guilin\web-ssm\target\webssm\WEB-INF\lib\mysql-connector-java-5.1.29.jar"/>
11 
12     <context id="default" targetRuntime="MyBatis3Simple" defaultModelType="flat">
13         <!-- optional,旨在創建class時,對注釋進行控制 -->
14         <commentGenerator>
15             <property name="suppressDate" value="true"/>
16         </commentGenerator>
17 
18         <!--jdbc的數據庫連接 -->
19         <jdbcConnection driverClass="com.mysql.jdbc.Driver"
20                         connectionURL="jdbc:mysql://172.21.1.28/thatday"
21                         userId="thatday"
22                         password="Thatday@123">
23         </jdbcConnection>
24 
25         <!-- 非必需,類型處理器,在數據庫類型和java類型之間的轉換控制-->
26         <javaTypeResolver>
27             <property name="forceBigDecimals" value="false"/>
28         </javaTypeResolver>
29 
30         <!-- Model模型生成器,用來生成含有主鍵key的類,記錄類 以及查詢Example類
31             targetPackage     指定生成的model生成所在的包名
32             targetProject     指定在該項目下所在的路徑
33         -->
34         <javaModelGenerator targetPackage="com.puyun.common.po" targetProject="src/main/java">
35             <!-- 是否對model添加 構造函數 -->
36             <property name="constructorBased" value="false"/>
37 
38             <!-- 是否允許子包,即targetPackage.schemaName.tableName -->
39             <property name="enableSubPackages" value="false"/>
40 
41             <!-- 建立的Model對象是否 不可改變  即生成的Model對象不會有 setter方法,只有構造方法 -->
42             <property name="immutable" value="false"/>
43 
44             <!-- 給Model添加一個父類 -->
45             <!--<property name="rootClass" value="com.foo.louis.Hello"/>-->
46 
47             <!-- 是否對類CHAR類型的列的數據進行trim操作 -->
48             <property name="trimStrings" value="true"/>
49         </javaModelGenerator>
50         <!--生成映射文件存放位置-->
51                  <!--<sqlMapGenerator targetPackage="com.puyun.common.dao" targetProject="src/main/java">-->
52                     <!--<property name="enableSubPackages" value="true"/>-->
53                 <!--</sqlMapGenerator>-->
54                  <!--&lt;!&ndash;生成Dao類存放位置&ndash;&gt;-->
55                  <!--<javaClientGenerator type="XMLMAPPER" targetPackage="com.puyun.common.dao" targetProject="src/main/java">-->
56                      <!--<property name="enableSubPackages" value="true"/>-->
57                 <!--</javaClientGenerator>-->
58         <!-- 客戶端代碼,生成易於使用的針對Model對象和XML配置文件 的代碼
59                 type="ANNOTATEDMAPPER",生成Java Model 和基於注解的Mapper對象
60                 type="MIXEDMAPPER",生成基於注解的Java Model 和相應的Mapper對象
61                 type="XMLMAPPER",生成SQLMap XML文件和獨立的Mapper接口
62         -->
63         <javaClientGenerator targetPackage="com.puyun.common.dao" targetProject="src/main/java"
64                              type="ANNOTATEDMAPPER">
65         </javaClientGenerator>
66             <!--<table tableName="t_admin" domainObjectName="AdminEntity"></table>-->
67             <!--<table tableName="t_advertising" domainObjectName="AdvertisingEntity"></table>-->
68             <!--<table tableName="t_area" domainObjectName="AreaEntity"></table>-->
69             <!--<table tableName="t_automat" domainObjectName="AutomatEntity"></table>-->
70             <!--<table tableName="t_automatrunstate" domainObjectName="AutomatrunstateEntity"></table>-->
71             <!--<table tableName="t_automatrunstate_log" domainObjectName="AutomatrunstateLogEntity"></table>-->
72             <!--<table tableName="t_goods" domainObjectName="GoodsEntity"></table>-->
73             <!--<table tableName="t_goodstype" domainObjectName="GoodstypeEntity"></table>-->
74             <!--<table tableName="t_maintainlog" domainObjectName="MaintainlogEntity"></table>-->
75             <!--<table tableName="t_notice" domainObjectName="NoticeEntity"></table>-->
76             <!--<table tableName="t_order" domainObjectName="OrderEntity"></table>-->
77             <!--<table tableName="t_orderitem" domainObjectName="OrderitemEntity"></table>-->
78             <!--<table tableName="t_rel_admin_automat" domainObjectName="ReladminautomatEntity"></table>-->
79             <!--<table tableName="t_repair" domainObjectName="RepairEntity"></table>-->
80             <!--<table tableName="t_shipmentslog" domainObjectName="ShipmentslogEntity"></table>-->
81             <!--<table tableName="t_stock" domainObjectName="StockEntity"></table>-->
82             <!--<table tableName="t_warnlog" domainObjectName="WarnlogEntity"></table>-->
83             <!--<table tableName="t_opendoortemp" domainObjectName="OpenDoorTempEntity"></table>-->
84         <!--<table tableName="t_statisticsday" domainObjectName="StatisticsDayEntity"></table>-->
85             <!--<table tableName="t_user" domainObjectName="UserEntity"></table>-->
86         <table tableName="t_fault_order" domainObjectName="FaultOrderEntity"></table>
87     </context>
88 </generatorConfiguration>

注意第十行代碼 那個jar包要改為你本機上面jar的位置


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM