zoukankan      html  css  js  c++  java
  • MyBatis Generator自动创建代码

            MyBatis Generator自动创建代码

        1.首先在eclipse上安装mybatis插件

            

         2.创建一个mavenWeb项目。

            

         3.在resource中写入一个xml,一定要与我得同名

           

     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 <generatorConfiguration>
     6     <properties resource="db.properties" />
     7     <context id="mysqlTables" targetRuntime="MyBatis3">
     8         <jdbcConnection driverClass="${jdbc.driver}"
     9             connectionURL="${jdbc.url}" userId="${jdbc.username}" password="${jdbc.password}" />
    10         <!--指定生成的类型为java类型,避免数据库中number等类型字段 -->
    11         <javaTypeResolver>
    12             <property name="forceBigDecimals" value="false" />
    13         </javaTypeResolver>
    14         <!--自动生成的实体的存放包路径 -->
    15         <javaModelGenerator targetPackage="com.bw.pojo"
    16             targetProject="src/main/java">
    17             <property name="enableSubPackages" value="true" />
    18             <property name="trimStrings" value="true" />
    19         </javaModelGenerator>
    20         <!--自动生成的*Mapper.xml文件存放路径 -->
    21         <sqlMapGenerator targetPackage="com.bw.mapper"
    22             targetProject="src/main/java">
    23             <property name="enableSubPackages" value="true" />
    24         </sqlMapGenerator>
    25         <!--自动生成的*Mapper.java存放路径 -->
    26         <javaClientGenerator type="XMLMAPPER"
    27             targetPackage="com.bw.mapper" targetProject="src/main/java">
    28             <property name="enableSubPackages" value="true" />
    29         </javaClientGenerator>
    30         <table tableName="user" domainObjectName="User"
    31             enableCountByExample="false" enableUpdateByExample="false"
    32             enableDeleteByExample="false" enableSelectByExample="false"
    33             selectByExampleQueryId="false"></table>
    34     </context>
    35 </generatorConfiguration>

     1)此时table为我数据库中的表。

     2)这行是我写的数据库连接properties文件。你必须对应resource的位置写一个

           

     3)注意一定要创建你生成文件的位置,如com.**.pojo;com.**.mapper...等等

         4.注意,右键-->run As, --> mavenBuild ,在Goals中填 mybatis-generator:generate,直接点击run

            

          5.结果:

            

        不积小流无以成江海,不积硅步无以至千里。

  • 相关阅读:
    sql行列互换
    转: 在hibernate中查询使用list,map定制返回类型
    拦截器和过滤器的区
    hibernate 实体对象的三种状态以及转换关系。
    如何理解Hibernate的延迟加载机制?在实际应用中,延迟加载与Session关闭的矛盾是如何处理的?
    Hibernate常见优化策略
    Hibernate的一级缓存、二级缓存和查询缓存。
    关于java Collections.sort 排序
    常用颜色,正则表达式工具
    java正则表达式
  • 原文地址:https://www.cnblogs.com/meiLinYa/p/8918914.html
Copyright © 2011-2022 走看看