maven+springboot+mybatis+mysql+myeclipse(mybatis-generator生成代码配置)

1、mybatis-generator插件生成

在pom.xml中添加如下代码,<pluginManagement> </pluginManagement>如果未报错,这个可以不要,具体可以参考[https://blog.csdn.net/l3922768721/article/details/79913346]

 <build>
   <pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
      <!-- 使用完后注释掉 -->
      <plugin>  
             <groupId>org.mybatis.generator</groupId>  
             <artifactId>mybatis-generator-maven-plugin</artifactId>  
             <version>1.3.2</version>  
              <configuration>  
                    **<!--配置文件的位置-->**  
             <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
                 **<!--允许移动生成的文件 -->** 
                  <verbose>true</verbose>  
                  **<!-- 是否覆盖 -->**
                  <overwrite>false</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.3.2</version>  
                  </dependency>  
              </dependencies>  
          </plugin>
    </plugins>
    </pluginManagement>

2、generatorConfig.xml配置

如果报错,请参考https://blog.csdn.net/l3922768721/article/details/79914281

<?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>  

    <properties resource="application.properties" />  

    <classPathEntry location="${jdbc.location}" />  

    <context id="Tables" targetRuntime="MyBatis3">  

        <!-- 注释 -->  
        <commentGenerator>  
            <!-- 是否生成注释代时间戳 -->  
            <property name="suppressDate" value="true"/>  
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
            <property name="suppressAllComments" value="true"/>  
        </commentGenerator>  

        <!-- JDBC连接 -->  
       <jdbcConnection  
                driverClass="${spring.datasource.driver-class-name}"  
                connectionURL="${spring.datasource.url}"  
                userId="${spring.datasource.username}"  
                password="${spring.datasource.password}">  
        </jdbcConnection>
       <!--  <jdbcConnection 
            driverClass="com.mysql.jdbc.Driver" 
            connectionURL="jdbc:mysql://rm-2zeaa9v14zi7fi9opo.mysql.rds.aliyuncs.com:3306/database"
            userId="" 
            password="">  
        </jdbcConnection>  --> 
        <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和   NUMERIC 类型解析为java.math.BigDecimal -->
        <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->  

        <javaTypeResolver>  
            <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->  
            <property name="forceBigDecimals" value="false" />  
        </javaTypeResolver>  

        <!-- 生成实体类地址 -->  
        <javaModelGenerator targetPackage="com.wd.hospital.entity" targetProject="src/main/java">  
            <!-- 从数据库返回的值被清理前后的空格 -->  
            <property name="trimStrings" value="true" />  
            <!-- enableSubPackages:是否让schema作为包的后缀 -->  
            <property name="enableSubPackages" value="false" />  
        </javaModelGenerator>  

        <!-- 生成mapper xml文件 -->  
        <sqlMapGenerator targetPackage="mapper"  targetProject="src/main/resources">  
            <!-- enableSubPackages:是否让schema作为包的后缀 -->  
            <property name="enableSubPackages" value="false" />  
        </sqlMapGenerator>  

        <!-- 生成mapper xml对应Client-->  
        <javaClientGenerator targetPackage="com.wd.hospital.mapper" targetProject="src/main/java" type="XMLMAPPER">  
            <!-- enableSubPackages:是否让schema作为包的后缀 -->  
            <property name="enableSubPackages" value="false" />  
        </javaClientGenerator>  

        <!-- 配置表信息 -->  
        <!-- schema即为数据库名
         tableName为对应的数据库表 
         domainObjectName是要生成的实体类 
         enable*ByExample  
                是否生成 example类 -->  

        <table schema="jfdb" tableName="sys_user"  
        domainObjectName="UserTest" enableCountByExample="true"  
        enableDeleteByExample="true" enableSelectByExample="true"  
        enableUpdateByExample="true">  
        </table>  

        <!--<table schema="blog" tableName="article"-->  
        <!--domainObjectName="Article" enableCountByExample="false"-->  
        <!--enableDeleteByExample="false" enableSelectByExample="false"-->  
        <!--enableUpdateByExample="false">-->  
        <!--</table>-->  

        <!--<table schema="blog" tableName="document"-->  
        <!--domainObjectName="Document" enableCountByExample="false"-->  
        <!--enableDeleteByExample="false" enableSelectByExample="false"-->  
        <!--enableUpdateByExample="false">-->  
        <!--</table>-->  

        <!--<table schema="blog" tableName="tag"-->  
        <!--domainObjectName="Tag" enableCountByExample="false"-->  
        <!--enableDeleteByExample="false" enableSelectByExample="false"-->  
        <!--enableUpdateByExample="false">-->  
        <!--</table>-->  

    </context>  
</generatorConfiguration>  

3、application.properties配置

jdbc.location=G:/nanjing/DC_CLOUD/20180123-ly/mysde/workspace/MAVEN2/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar

4、运行

RUN AS ->Maven build(后面带快捷键的那个共两个),选择下面一个运行。运行结果如下

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building HospitalApp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- mybatis-generator-maven-plugin:1.3.2:generate (default-cli) @ HospitalApp ---
[INFO] Connecting to the Database
Thu Apr 12 15:25:41 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
[INFO] Introspecting table jfdb.sys_user
log4j:WARN No appenders could be found for logger (org.mybatis.generator.internal.db.DatabaseIntrospector).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[INFO] Generating Example class for table sys_user
[INFO] Generating Primary Key class for table sys_user
[INFO] Generating Record class for table sys_user
[INFO] Generating Mapper Interface for table sys_user
[INFO] Generating SQL Map for table sys_user
[INFO] Saving file UserTestMapper.xml
[INFO] Saving file UserTestExample.java
[INFO] Saving file UserTestKey.java
[INFO] Saving file UserTest.java
[INFO] Saving file UserTestMapper.java
[WARNING] Existing file H:\jwx\HospitalApp\src\main\java\com\wd\hospital\entity\UserTestExample.java was overwritten
[WARNING] Existing file H:\jwx\HospitalApp\src\main\java\com\wd\hospital\entity\UserTestKey.java was overwritten
[WARNING] Existing file H:\jwx\HospitalApp\src\main\java\com\wd\hospital\entity\UserTest.java was overwritten
[WARNING] Existing file H:\jwx\HospitalApp\src\main\java\com\wd\hospital\mapper\UserTestMapper.java was overwritten
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.613 s
[INFO] Finished at: 2018-04-12T15:25:41+08:00
[INFO] Final Memory: 23M/217M
[INFO] ------------------------------------------------------------------------

5、目录结构

(1)、总的目录结构

这里写图片描述

(2)、代码自动生成前目录结构

这里写图片描述

(3)、代码自动生成后目录结构

这里写图片描述

6、源码

https://download.csdn.net/download/l3922768721/10344252

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值