mybatis自动生成代码xml配置文件

来源:互联网 发布:淘宝质检报告怎么上传 编辑:程序博客网 时间:2024/06/04 18:56

<?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">

<!-- 配置mysql 驱动jar包路径.用了绝对路径 -->
<generatorConfiguration>
  <classPathEntry location="C:\Users\user\.m2\repository\mysql\mysql-connector-java\5.1.18\mysql-connector-java-5.1.18.jar" />

<context id="lyx_mybatis_tables" targetRuntime="MyBatis3">
 
  <!-- 为了防止生成的代码中有很多注释,比较难看,加入下面的配置控制 -->
<!--     <commentGenerator> -->
<!--       <property name="suppressAllComments" value="true" /> -->
<!--       <property name="suppressDate" value="true" /> -->
<!--     </commentGenerator> -->
    <!-- 注释控制完毕 -->
   
   <!-- 数据库连接 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
        connectionURL="jdbc:mysql://localhost:3306/mybatis"
        userId="root"
        password="root">
    </jdbcConnection>

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

 <!-- 数据表对应的model 层  -->
    <javaModelGenerator targetPackage="com.lyx.model" targetProject="d:\lib\src">
      <property name="enableSubPackages" value="true" />
      <property name="trimStrings" value="true" />
    </javaModelGenerator>

<!-- sql mapper 映射配置文件 -->
    <sqlMapGenerator targetPackage="com.lyx.mapper"  targetProject="d:\lib\src">
      <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>

<!-- 在ibatis2 中是dao层,但在mybatis3中,其实就是mapper接口 -->
    <javaClientGenerator type="XMLMAPPER" targetPackage="com.lyx.inter"  targetProject="d:\lib\src">
      <property name="enableSubPackages" value="true" />
    </javaClientGenerator>

<!-- 要对那些数据表进行生成操作,必须要有一个. -->
<!-- 写了connectionURL可以不写schema -->
    <table schema="mybatis" tableName="category"  domainObjectName="Category"
    enableCountByExample="false" enableUpdateByExample="false"
    enableDeleteByExample="false" enableSelectByExample="false"
    selectByExampleQueryId="false">    
    </table>

  </context>
</generatorConfiguration>

原创粉丝点击