MyBatis逆向生成使用
一、导入Mybatis-generator逆向插件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
   | <plugins>                                      <plugin>                 <groupId>org.mybatis.generator</groupId>                 <artifactId>mybatis-generator-maven-plugin</artifactId>                 <version>1.4.1</version>                 <configuration>                                          <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>                     <verbose>true</verbose>                                          <overwrite>true</overwrite>                 </configuration>                 <executions>                     <execution>                         <id>Generate MyBatis Artifacts</id>                         <goals>                             <goal>generate</goal>                         </goals>                     </execution>                 </executions>                                 <dependencies>                     <dependency>                         <groupId>org.mybatis.generator</groupId>                         <artifactId>mybatis-generator-core</artifactId>                         <version>1.4.1</version>                     </dependency>                                          <dependency>                         <groupId>mysql</groupId>                         <artifactId>mysql-connector-java</artifactId>                         <version>8.0.33</version>                     </dependency>                 </dependencies>             </plugin>       </plugins>
 
   | 
 
这里需要注意一下configurationFile对应配置信息的内容,这里的路径对应之后需要你创建的配置文件路径。
二、创建MyBatis逆向配置文件
以下为配置文件模板
generatorConfig.xml:注意此配置文件所在地方为第一步中插件配置中指定的路径
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
   | <?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>     
 
 
      
      
 
 
 
      <context id="testTables" targetRuntime="MyBatis3">                  <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin"/>         <commentGenerator>                          <property name="suppressDate" value="true"/>                          <property name="suppressAllComments" value="true"/>         </commentGenerator>
                   <jdbcConnection driverClass="com.mysql.jdbc.Driver"                         connectionURL="jdbc:mysql://localhost:3306/smstwo"                         userId="root"                         password="ht520520">         </jdbcConnection>
          
          <javaTypeResolver>             <property name="forceBigDecimals" value="false"/>         </javaTypeResolver>
          
 
 
          <javaModelGenerator targetPackage="com.SMS.domain" targetProject="src/main/java">                          <property name="enableSubPackages" value="false"/>                          <property name="trimStrings" value="true"/>         </javaModelGenerator>
          
          <sqlMapGenerator targetPackage="com.SMS.dao" targetProject="src/main/java">             <property name="enableSubPackages" value="false"/>         </sqlMapGenerator>         
 
          
 
          <javaClientGenerator type="XMLMAPPER"                              targetPackage="com.SMS.dao"                              targetProject="src/main/java">             <property name="enableSubPackages" value="false"/>         </javaClientGenerator>
          
 
 
          <table tableName="t_userlogin" domainObjectName="User"></table>         <table tableName="t_class" domainObjectName="MyClass"></table>         <table tableName="t_course" domainObjectName="Course"></table>         <table tableName="t_dept" domainObjectName="Dept"></table>         <table tableName="t_leave" domainObjectName="Leave"></table>         <table tableName="t_student" domainObjectName="Student"></table>         <table tableName="t_tearcher" domainObjectName="Tearcher"></table>     </context> </generatorConfiguration>
 
   |