• (原创)mybatis学习四,利用mybatis自动创建代码


      在使用mybatis的过程中,我们可以直接利用MyBatis生成器自动生成实体类、DAO接口和Mapping映射文件,然后copy到工程中即可

      需要的jar包如下

    下载路径如下:下载jar包

    其中的generatorConfig.cml的内容如下:

     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 <!-- 数据库驱动-->  
     7     <classPathEntry  location="mysql-connector-java-5.1.18-bin.jar"/>  
     8     <context id="DB2Tables"  targetRuntime="MyBatis3">  
     9         <commentGenerator>  
    10             <property name="suppressDate" value="true"/>  
    11             <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
    12             <property name="suppressAllComments" value="true"/>  
    13         </commentGenerator>  
    14         <!--数据库链接URL,用户名、密码 -->  
    15         <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/mybatis" userId="root" password="123456">  
    16         </jdbcConnection>  
    17         <javaTypeResolver>  
    18             <property name="forceBigDecimals" value="false"/>  
    19         </javaTypeResolver>  
    20         <!-- 生成模型的包名和位置-->  
    21         <javaModelGenerator targetPackage="com.unis" targetProject="src">  
    22             <property name="enableSubPackages" value="true"/>  
    23             <property name="trimStrings" value="true"/>  
    24         </javaModelGenerator>  
    25         <!-- 生成映射文件的包名和位置-->  
    26         <sqlMapGenerator targetPackage="com.unis.mapping" targetProject="src">  
    27             <property name="enableSubPackages" value="true"/>  
    28         </sqlMapGenerator>  
    29         <!-- 生成DAO的包名和位置-->  
    30         <javaClientGenerator type="XMLMAPPER" targetPackage="com.unis.IDao" targetProject="src">  
    31             <property name="enableSubPackages" value="true"/>  
    32         </javaClientGenerator>  
    33         <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->  
    34         <table tableName="users" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
    35     </context>  
    36 </generatorConfiguration>  
    properties

      完成上述操作后,进入目录里面,然后执行下面的cmd指令即可

        java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite

      结果如下面所示

  • 相关阅读:
    关于全景漫游
    webgl圈中物体
    css3の极限
    reactjs弹幕视频播放
    数值积分I
    显出你的h5逼格
    奇葩のbeforeunload
    面试问题搜集及解析
    TCP拥塞控制(滑动窗口机制)
    如何使CPU占用率为50%
  • 原文地址:https://www.cnblogs.com/ningheshutong/p/5776691.html
Copyright © 2020-2023  润新知