Maven下 mybatis-generator使用

1. pom.xml下添加dependency

<dependency>

  <groupId>org.mybatis.generator</groupId>

  <artifactId>mybatis-generator-core</artifactId>

  <version>1.3.2</version>

</dependency>

  2. pom.xml下plugins插入plugin

<plugin>

  <groupId>org.mybatis.generator</groupId>

  <artifactId>mybatis-generator-maven-plugin</artifactId>

  <version>1.3.2</version>

  <goals>

    <glal>generator</glal>

  </goals>

  <configuration>

    <verbose>true</verbose>

    <overwrite>true</overwrite>

  </configuration>

</plugin>

   3. src/main/resource下创建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>

<classPathEntry location="D:\RepositoryGit\MyBatisGenerator1.3.5\mysql-connector-java-5.1.36.jar" />

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

  <!-- 生成的‘实体类'将implements Serializable -->

  <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>

  <!-- 是否生成注释-->

  <commentGenerator>

    <property name="suppressAllComments" value="true" />

    <property name="suppressDate" value="true" />

  </commentGenerator>

  <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/test"

   userId="root" password="mysql" />

  <!--指定生成的类型为java类型,避免数据库中number等类型字段 -->

  <javaTypeResolver>

    <property name="forceBigDecimals" value="false" />

  </javaTypeResolver>

  <!--自动生成的实体的存放包路径 -->

  <javaModelGenerator targetPackage="com.example.dao.mybatis.entity" targetProject="src/main/java">

  <property name="enableSubPackages" value="true" />

    <property name="trimStrings" value="true" />

  </javaModelGenerator>

  <!--自动生成的*Mapper.xml文件存放路径 -->

  <sqlMapGenerator targetPackage="com.example.dao.mybatis.sqlMap" targetProject="src/main/java">

    <property name="enableSubPackages" value="true" />

  </sqlMapGenerator>

  <!--自动生成的*Mapper.java存放路径 -->

  <javaClientGenerator type="XMLMAPPER" targetPackage="com.example.dao.mybatis.mapper"

     targetProject="src/main/java">

    <property name="enableSubPackages" value="true" />

  </javaClientGenerator>

  <table tableName="user" domainObjectName="User"

  enableCountByExample="false" enableUpdateByExample="false"

  enableDeleteByExample="false" enableSelectByExample="false"

  selectByExampleQueryId="false">

  <generatedKey column="id"

  sqlStatement="SELECT LAST_INSERT_ID()" identity="false" />

  </table>

</context>

</generatorConfiguration>

4. 执行mybatis-generator:generate运行生成实体类、mapper和XML映射文件

总结

以上所述是小编给大家介绍的Maven下 mybatis-generator使用,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

以上是 Maven下 mybatis-generator使用 的全部内容, 来源链接: utcz.com/z/318967.html

回到顶部