zoukankan      html  css  js  c++  java
  • mybatis_generator_逆向工程的使用笔记

    1:解压mybatis_generator_1.3.1.zip文件。

    2:把features,pougins文件夹copy到D:javaeclipseeclipse目录下(D:javaeclipseeclipse为eclipse的安装目录)。

    3:进入D:javaeclipseeclipsedropins目录,并新建mybatis.link文件,添加内容:path=D:javaeclipseeclipse

    4:启动eclipse。

    5:项目中添加generatorConfig.xml文件,并修改相关内容。右建可以找到generator mybatis artifacts生成。操作如下所示:

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <!DOCTYPE generatorConfiguration
     3   PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
     4   "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
     5 
     6 <generatorConfiguration>
     7     <!--
     8         <properties resource="conn.properties" />
     9     -->
    10     <!-- 处理1 -->
    11     <classPathEntry location="D:javamysql-connector-java-5.1.8.jar"/>
    12     <!-- 指定运行环境是mybatis3的版本 -->
    13     <context id="testTables" targetRuntime="MyBatis3">
    14 
    15         <commentGenerator>
    16         <!-- 是否取消注释 -->
    17             <property name="suppressAllComments" value="true" />
    18              <!-- 是否生成注释代时间戳 -->
    19             <property name="suppressDate" value="true" />
    20         </commentGenerator>
    21         <!-- 处理2   jdbc 连接信息 -->
    22         <jdbcConnection 
    23             driverClass="com.mysql.jdbc.Driver"
    24             connectionURL="jdbc:mysql://localhost:3306/jxc?useUnicode=true&amp;characterEncoding=UTF-8" 
    25             userId="root" 
    26             password="123456">
    27         </jdbcConnection>
    28         
    29         <!--处理3   targetPackage指定模型在生成在哪个包 ,targetProject指定项目的src,-->        
    30         <javaModelGenerator targetPackage="com.bie.po"
    31             targetProject="JXC/src/main/resources">
    32             <!-- 去除字段前后空格 -->
    33             <property name="trimStrings" value="false" />
    34         </javaModelGenerator>
    35         <!--处理4   配置SQL映射文件生成信息 -->
    36         <sqlMapGenerator targetPackage="com.bie.dao"
    37             targetProject="JXC/src/main/resources" />
    38         <!-- 处理5   配置dao接口生成信息-->
    39         <javaClientGenerator type="XMLMAPPER" targetPackage="com.bie.dao" targetProject="JXC/src/main/resources" />
    40         
    41         <!-- 
    42             处理6 修改自己对应的数据表和实体类的类名称 
    43             注意:如果添加其他数据表,将下面这些注释以后再添加,然后执行。    
    44         -->
    45         <table tableName="jxc_admin" domainObjectName="JxcAdmin"/>
    46         <table tableName="jxc_customer" domainObjectName="JxcCustomer"/>
    47         <table tableName="jxc_employee" domainObjectName="JxcEmployee"/>
    48         <table tableName="jxc_goods" domainObjectName="JxcGoods"/>
    49         <table tableName="jxc_log" domainObjectName="JxcLog"/>
    50         <table tableName="jxc_menu" domainObjectName="JxcMenu"/>
    51         <table tableName="jxc_purchaseorder" domainObjectName="JxcPurchaseorder"/>
    52         <table tableName="jxc_role" domainObjectName="JxcRole"/>
    53         <table tableName="jxc_salesorder" domainObjectName="JxcSalesorder"/>
    54         <table tableName="jxc_stock" domainObjectName="JxcStock"/>
    55         <table tableName="jxc_supplier" domainObjectName="JxcSupplier"/>
    56         <table tableName="jxc_warehouse" domainObjectName="JxcWarehouse"/>
    57     </context>
    58     
    59 </generatorConfiguration>

     操作如下所示:

    最后在实体类包里面将xxxExample.java文件全部删除即可。即完成自动生成实体类和dao层接口和xxxmapper.xml映射文件。

    注意:完成后记得把实体实现Serializable,重写一下toString()方法,方便以后使用。

  • 相关阅读:
    Math类操作数据
    java之静态方法与非静态方法
    使用Date和SimpleDateFormat类表示时间
    Java 中基本类型和字符串之间的转换
    Python基础
    生成对抗网络
    机器翻译
    语义角色标注
    个性化推荐
    词向量
  • 原文地址:https://www.cnblogs.com/biehongli/p/8452749.html
Copyright © 2011-2022 走看看