****

mybatis官方为了提高开发效率,提高自动对单表生成sql,包括 :mapper.xml、mapper.java、表名.java(实体类)

 

1.第一步打开eclipse的插件市场

****

2、搜索mybaits-generator插件,并安装

****

3.耐心等待...

4.新建工程加入jar包

****

 

generatorConfig.xml代码

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

<generatorConfiguration>

  <context id="context1">

  <!-- 取消注释 -->

  <!-- org.mybatis.generator.config.PropertyRegistry -->

  <commentGenerator>

    <property name="suppressAllComments" value="true"/>

  </commentGenerator>

  <!-- 数据库连接 -->

    <jdbcConnection connectionURL="jdbc:mysql://localhost:3307/mybatis_clazz_day03" driverClass="com.mysql.jdbc.Driver" password="root" userId="root" />

     <!-- 实体类的目录 -->

    <javaModelGenerator targetPackage="com.ysjt.entity" targetProject="mybatis_demo20_day05_generator" />

    <!-- 映射文件的目录 -->

    <sqlMapGenerator targetPackage="com.ysjt.mapper.xml" targetProject="mybatis_demo20_day05_generator">

         <property name="enableSubPackages" value="true" />

    </sqlMapGenerator>

    <!-- 映射接口的目录

    type:表示生成策略,

       XMLMAPPER       配置xml

       ANNOTATEDMAPPER  配置注解

    targetPackage:存放的包

    targetProject:项目名

    -->

    <javaClientGenerator targetPackage="com.ysjt.mapper" targetProject="mybatis_demo20_day05_generator" type="ANNOTATEDMAPPER" />

    <table  tableName="student" enableCountByExample="false" enableSelectByExample="false" enableUpdateByExample="false"  enableDeleteByExample="false"></table>

    <table tableName="course"  enableCountByExample="false" enableSelectByExample="false" enableUpdateByExample="false"  enableDeleteByExample="false"></table>

    <table tableName="teacher"  enableCountByExample="false" enableSelectByExample="false" enableUpdateByExample="false"  enableDeleteByExample="false"></table>

    <table tableName="address"  enableCountByExample="false" enableSelectByExample="false" enableUpdateByExample="false"  enableDeleteByExample="false"></table>

  </context>

</generatorConfiguration>

 

选中generatorConfig.xml右键

****