zoukankan      html  css  js  c++  java
  • 使用Mybatis插件generator自动生成代码

    使用MyBatis插件generator通过连接数据库自动生成实体类,Mapper.xml,dao等文件

    1、pom引用包

    <dependency>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-core</artifactId>
                <version>1.3.2</version>
            </dependency>
    <!-- 这个包是写了分页的工具包-->
            <dependency>
                <groupId>yhqutil</groupId>
                <artifactId>yhqutil</artifactId>
                <version>1.0</version>
            </dependency>
    <!-- 编译配置-->
    <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.2</version>
        <configuration>
       <configurationFile>${basedir}/src/main/resources/mybatis/generatorConfig.xml</configurationFile>
            <verbose>false</verbose>
            <overwrite>true</overwrite>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-core</artifactId>
                       <version>1.3.2</version>
            </dependency>
            <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.11</version>
        </dependency>
            <dependency>
                <groupId>yhqutil</groupId>
                <artifactId>yhqutil</artifactId>
                <version>1.0</version>
            </dependency>
        </dependencies>
    </plugin>

    2、generatorConfig.xml文件配置

    <?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="my" targetRuntime="MyBatis3">
            <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
            <plugin type="com.yhq.util.MySQLLimitPlugin"></plugin>
            <commentGenerator>
                <property name="suppressDate" value="false"/>

       //重复生成 <property name="suppressAllComments" value="false"/> </commentGenerator> <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/yhqdb?useSSL=false&amp;serverTimezone=UTC" userId="yhq" password="yhq" ></jdbcConnection> <javaModelGenerator targetPackage="com.MultipleDataSource.entities" targetProject="src/main/java"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- sqlMapGenerator标签是生成mapper.xml --> <sqlMapGenerator targetPackage="mappers" targetProject="src/main/resources"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- javaClientGenerator标签是生成dao --> <javaClientGenerator targetPackage="com.MultipleDataSource.mapper" targetProject="src/main/java" type="XMLMAPPER"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!--<table tableName="T_FEE_AGTBILL" domainObjectName="FeeAgentBill" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <table tableName="kpoint" domainObjectName="KnowledgePoint"> <!--<columnRenamingRule searchString="^D_" replaceString=""/>--> </table> </context> </generatorConfiguration>

    3、maveny启动generator命令

    mvn mybatis-generator:generate

    http://mybatis.org/generator/running/runningWithMaven.html

  • 相关阅读:
    HttpServletRequest和HttpServletResponse实例
    ioc autofac简单示例
    sql left join 字符串
    sqlserver split函数
    类型同时存在于A.dll和B.dll中的解决办法
    ef使用dbfirst方式连接mysql
    html5 图片上传 预览
    webservice使用EF生成的model序列化问题
    sqlserver2008数据库文件降级为sqlserver2005文件
    [转]webapi部署在IIS7.5报404的解决方案
  • 原文地址:https://www.cnblogs.com/yuhuiqing/p/10686832.html
Copyright © 2011-2022 走看看