Eclipse中mybatis自动生成代码

来源:互联网 发布:怎么当淘宝店铺客服 编辑:程序博客网 时间:2024/05/17 21:44

工具下载

  1. Eclipse中help–>install new software
  2. 如下图所示
    这里写图片描述
    Location:内容
  3. 完成安装之后,选择新建–Ctrl + N之后,生成generateConfig.xml文件

GenerateConfig.xml文件

  1. 配置GenerateConfig.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>    <classPathEntry        location="C:\Users\baiju\.m2\repository\mysql\mysql-connector-java\5.1.30\mysql-connector-java-5.1.30.jar" />    <context id="context1">        <!-- 去掉生成出来的代码的注解 -->        <commentGenerator>            <property name="suppressAllComments" value="true" />            <property name="suppressDate" value="true" />        </commentGenerator>        <jdbcConnection driverClass="com.mysql.jdbc.Driver"            connectionURL="jdbc:mysql:///mybatis" userId="root" password="920512" />        <!-- 生成模型的包名和位置 -->        <javaModelGenerator targetPackage="com.future.study.domain"            targetProject="future/java">            <property name="enableSubPackages" value="true" />            <property name="trimStrings" value="true" />        </javaModelGenerator>        <!-- 生成映射文件的包名和位置 -->        <sqlMapGenerator targetPackage="test.mapping"            targetProject="future/java">            <property name="enableSubPackages" value="true" />        </sqlMapGenerator>        <!-- 生成DAO的包名和位置 -->        <javaClientGenerator type="XMLMAPPER"            targetPackage="com.future.study.mapper" targetProject="future/java">            <property name="enableSubPackages" value="true" />        </javaClientGenerator>        <!-- 要生成哪些表 -->        <table tableName="classinfo" domainObjectName="ClassInfo"            enableCountByExample="false" enableUpdateByExample="false"            enableDeleteByExample="false" enableSelectByExample="false"            selectByExampleQueryId="false"></table>        <table tableName="course" domainObjectName="Course"            enableCountByExample="false" enableUpdateByExample="false"            enableDeleteByExample="false" enableSelectByExample="false"            selectByExampleQueryId="false"></table>        <table tableName="department" domainObjectName="Department"            enableCountByExample="false" enableUpdateByExample="false"            enableDeleteByExample="false" enableSelectByExample="false"            selectByExampleQueryId="false"></table>        <table tableName="namingrecord" domainObjectName="NamingRecord"            enableCountByExample="false" enableUpdateByExample="false"            enableDeleteByExample="false" enableSelectByExample="false"            selectByExampleQueryId="false"></table>        <table tableName="student" domainObjectName="Student"            enableCountByExample="false" enableUpdateByExample="false"            enableDeleteByExample="false" enableSelectByExample="false"            selectByExampleQueryId="false"></table>        <table tableName="supermin" domainObjectName="SuperAdmin"            enableCountByExample="false" enableUpdateByExample="false"            enableDeleteByExample="false" enableSelectByExample="false"            selectByExampleQueryId="false"></table>        <table tableName="teacher" domainObjectName="Teacher"            enableCountByExample="false" enableUpdateByExample="false"            enableDeleteByExample="false" enableSelectByExample="false"            selectByExampleQueryId="false"></table>        <table tableName="teacherclass" domainObjectName="TeacherClass"            enableCountByExample="false" enableUpdateByExample="false"            enableDeleteByExample="false" enableSelectByExample="false"            selectByExampleQueryId="false"></table>        <table tableName="teachercourse" domainObjectName="TeacherCourse"            enableCountByExample="false" enableUpdateByExample="false"            enableDeleteByExample="false" enableSelectByExample="false"            selectByExampleQueryId="false"></table>    </context></generatorConfiguration>  
  1. 在Eclipse中鼠标右键选中 generateConfig.xml文件,选择 Generate Mybatis/iBATIS Artifacts
0 0
原创粉丝点击