创建mybatis逆向工程(maven)

首先创建一个maven项目:
创建mybatis逆向工程(maven)_第1张图片

pom.xml:



<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0modelVersion>

  <groupId>com.generatorSqlMappergroupId>
  <artifactId>generatorSqlMapperartifactId>
  <version>1.0-SNAPSHOTversion>

  <name>generatorSqlMappername>

  <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.pluginsgroupId>
          <artifactId>maven-compiler-pluginartifactId>
          <configuration>
            <source>1.7source>
            <target>1.7target>
            <encoding>UTF-8encoding>
          configuration>
          <version>3.3version>
        plugin>
        
        <plugin>
          <groupId>org.mybatis.generatorgroupId>
          <artifactId>mybatis-generator-maven-pluginartifactId>
          <version>1.3.5version>
          <dependencies>
            <dependency>
              <groupId>mysqlgroupId>
              <artifactId>mysql-connector-javaartifactId>
              <version>5.1.38version>
            dependency>
          dependencies>
        plugin>
      plugins>
  build>
project>

在maven面板中可以看到该插件:
创建mybatis逆向工程(maven)_第2张图片

编写xml配置文件(该配置文件是淘淘商城的配置文件):




<generatorConfiguration>
    <context id="testTables" targetRuntime="MyBatis3">
        <commentGenerator>
            
            <property name="suppressAllComments" value="true" />
        commentGenerator>
        
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/taotao" userId="root"
                        password="123456">
        jdbcConnection>
        
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        javaTypeResolver>

        
        <javaModelGenerator targetPackage="com.taotao.pojo"
                            targetProject="src/main/java">
            
            <property name="enableSubPackages" value="false" />
            
            <property name="trimStrings" value="true" />
        javaModelGenerator>
        
        <sqlMapGenerator targetPackage="com.taotao.mapper"
                         targetProject="src/main/resources">
            
            <property name="enableSubPackages" value="false" />
        sqlMapGenerator>
        
        <javaClientGenerator type="XMLMAPPER"
                             targetPackage="com.taotao.mapper"
                             targetProject="src/main/java">
            
            <property name="enableSubPackages" value="false" />
        javaClientGenerator>
        
        <table schema="" tableName="tb_content">table>
        <table schema="" tableName="tb_content_category">table>
        <table schema="" tableName="tb_item">table>
        <table schema="" tableName="tb_item_cat">table>
        <table schema="" tableName="tb_item_desc">table>
        <table schema="" tableName="tb_item_param">table>
        <table schema="" tableName="tb_item_param_item">table>
        <table schema="" tableName="tb_order">table>
        <table schema="" tableName="tb_order_item">table>
        <table schema="" tableName="tb_order_shipping">table>
        <table schema="" tableName="tb_user">table>

    context>
generatorConfiguration>

然后运行插件生成mapper文件、接口跟pojo。

如果是eclipse的话,Run as->maven bulid->mybatis-generator:generate 执行 ->F5 刷新。

你可能感兴趣的:(创建mybatis逆向工程(maven))