美文网首页
mybatis generator使用(基于maven)

mybatis generator使用(基于maven)

作者: torres9gogogo | 来源:发表于2017-03-17 16:31 被阅读87次

1、添加maven依赖

<dependency>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.4</version>
</dependency>

2、添加插件

<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.4</version>
     <configuration>
        <verbose>true</verbose>
         <overwrite>true</overwrite>
     </configuration>
</plugin>

3、generator.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>
   <classPathEntry
           location="/Users/Torres/.m2/repository/mysql/mysql-connector-java/5.1.36/mysql-connector-java-5.1.36.jar"/>
   <context id="MysqlTables" targetRuntime="MyBatis3">
       <commentGenerator>
           <property name="suppressAllComments" value="true"/>
       </commentGenerator>
       <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                       connectionURL="jdbc:mysql://********:3306/extmail?characterEncoding=utf8"
                       userId="*****" password="****">
       </jdbcConnection>
       <javaTypeResolver>
           <property name="forceBigDecimals" value="false"/>
       </javaTypeResolver>
       <javaModelGenerator targetPackage="com.enniu.cloud.services.billcredit.model" targetProject="src/main/java">
           <property name="enableSubPackages" value="true"/>
           <property name="trimStrings" value="true"/>
           <property name="useActualColumnNames" value="true"/>
       </javaModelGenerator>
       <sqlMapGenerator targetPackage="mapper"
                        targetProject="src/main/resources">
           <property name="enableSubPackages" value="true"/>
       </sqlMapGenerator>
       <javaClientGenerator type="XMLMAPPER" targetPackage="com.enniu.cloud.services.billcredit.dao.mapper"
                            targetProject="src/main/java">
           <property name="enableSubPackages" value="true"/>
       </javaClientGenerator>
       <table tableName="T_UserCardExt" domainObjectName="UserCardExt" enableCountByExample="false"
              enableUpdateByExample="true" enableDeleteByExample="false" enableSelectByExample="true"
              selectByExampleQueryId="false">
      <property name="useActualColumnNames" value="true"/>
       </table>
   </context>
</generatorConfiguration>
*一定加 <property name="useActualColumnNames" value="true"/> 才能使生成的java model 字段命名为驼峰

4、进入项目,执行命令:mvn mybatis-generator:generate

Torres@Torress-MacBook-Pro server$ mvn mybatis-generator:generate

相关文章

网友评论

      本文标题:mybatis generator使用(基于maven)

      本文链接:https://www.haomeiwen.com/subject/gugenttx.html