码迷,mamicode.com
首页 > 移动开发 > 详细

mybatis自动生成mapper,dao映射文件

时间:2017-10-26 13:45:30      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:tab   classpath   截图   userinfo   需要   位置   app   type   ase   

利用Mybatis-Generator来帮我们自动生成mapper.xml文件,dao文件,model文件。

1、所需文件

关于Mybatis-Generator的下载可以到这个地址:https://github.com/mybatis/generator/releases

以下是相关文件截图:

技术分享

 

从以上截图中可以看出来有一个generator.xml文件,主要就是修改这个文件中的配置信息。

mybaits-generator-core-1032.jar为mybaits生成器的核心包。

mysql-connector-java-5.1.34.jar为连接mysql的jar包;ojdbc6.jar为连接oracle的jar包,根据需要选择不同的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> <!-- 数据库驱动包位置 --> <classPathEntry location="E:\web\java_mybits\generator\ojdbc6.jar" /> <!-- 本次我的数据库为oracle,所以选择此jar包 -->
  <!-- <classPathEntry location="C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" />--> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 数据库链接URL、用户名、密码 --> <!--<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhots:3306/my_db?characterEncoding=utf8" userId="root" password="123456">--> <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@11.10.97.14:1521:TESTOMS" userId="kfomswas" password="kfomswas"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成模型的包名和位置 --> <javaModelGenerator targetPackage="dh.model" targetProject="E:\web\java_mybits\generator\src"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成的映射文件包名和位置 --> <sqlMapGenerator targetPackage="dh.mapping" targetProject="E:\web\java_mybits\generator\src"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="dh.dao" targetProject="E:\web\java_mybits\generator\src"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- 要生成那些表(更改tableName和domainObjectName就可以) --> <table tableName="DH_DESIGN_TASK" domainObjectName="DhDesignTask" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<!--
          <table tableName="course_info" domainObjectName="CourseInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> <table tableName="course_user_info" domainObjectName="CourseUserInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
--> </context> </generatorConfiguration>

 如上代码所示:

修改下划线部分就能够生成相应的文件。多表一次性生成文件只需在上面的红色标注部分的注释释放掉,并修改相应的表名即可。

2、生成语句

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

3、生成步骤

技术分享

 

在该目录下的路径框内输入cmd,并按Enter,输入生成语句

技术分享

再回车之后显示:MyBatis Generator finished successfully

技术分享

在该目录下就生成了相应的文件

 相应的文件已上传至文件库。

mybatis自动生成mapper,dao映射文件

标签:tab   classpath   截图   userinfo   需要   位置   app   type   ase   

原文地址:http://www.cnblogs.com/xiangpeng/p/7735836.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!