码迷,mamicode.com
首页 > 其他好文 > 详细

利用mybatis-generator自动生成代码

时间:2018-12-23 20:45:27      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:word   drive   xxx   pack   pac   mysq   nbsp   comment   value   

  • 在pom.xml中添加plugin

 <plugins>
      <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.7</version>
        <configuration>
          <overwrite>true</overwrite>
          <verbose>true</verbose>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.mariadb.jdbc</groupId>
            <artifactId>mariadb-java-client</artifactId>
            <version>2.3.0</version>
          </dependency>
        </dependencies>
     </plugin>
  </plugins>
  • 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="mysql" targetRuntime="MyBatis3Simple">

        <commentGenerator>
            <property name="suppressDate" value="true"/>
        </commentGenerator>
        <!-- 数据库连接 -->
        <jdbcConnection driverClass="org.mariadb.jdbc.Driver"
                        connectionURL="jdbc:mariadb://localhost/xx"
                        userId="xxx" password="xxx">
        </jdbcConnection>

        <!-- Model生成规则 -->
        <javaModelGenerator targetPackage="com.lhy.Flower.entity" targetProject="src/main/java">
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/>
        <!-- dao 规则 -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.lhy.flower.dao" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <table tableName="%">
            <generatedKey column="id" sqlStatement="Mysql"/>
        </table>
    </context>
</generatorConfiguration>
  • 最后给出目录结构图:

    技术分享图片

 

利用mybatis-generator自动生成代码

标签:word   drive   xxx   pack   pac   mysq   nbsp   comment   value   

原文地址:https://www.cnblogs.com/lhy-549/p/10165393.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!