使用mybatis配置映射文件比较的麻烦,但是有自动生成jar工具,方便加速开发速度,下面主要是该工具的使用以及相关的配置。

1、下载相关的资源

我们需要下载mybatis-generator-core-1.3.2.jar,mysql-connector-java-5.1.34.jar(对应相关数据库的驱动包),generator.xml(配置文件)

    我的网盘全部相关下载地址:http://pan.baidu.com/s/1ntn48pb

    下载解压后会有 generator.xml  和两个 jar  一个是数据库驱动包,这个取决你自己使用什么数据库可更改,一个是mybatis-generator-core   generator的核心包 ,还有一个 生成model的命令文本。

 

2、配置generator.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="D:\generator\mysql-connector-java-5.1.34.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://localhost:3306/shop" userId="root" password="12345">
<!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa">-->
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="andy.model" targetProject="D:\generator\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成的映射文件包名和位置 -->
<sqlMapGenerator targetPackage="andy.mapping" targetProject="D:\generator\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="andy.dao" targetProject="D:\generator\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
<table tableName="user_info" domainObjectName="UserInfo" 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>

注意:

需要修改对应数据库的驱动文件位置,以数据库名密码。

设置对应的生成表的表名以及对应的类名,这样就自动生成了model,dao,mappding配置文件。

3、生成配置文件

   打开cmd,进入目录generator,执行命令

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

  

  执行完后就自动生成dao,mapping,model文件内容了。

  本博客转载源于:  http://blog.csdn.net/fengshizty/article/details/43086833

  仅供学习笔记使用,好记性不如烂笔头。

Mybatis使用generator自动生成映射配置文件信息的更多相关文章

  1. MyBatis使用Generator自动生成代码

    MyBatis中,可以使用Generator自动生成代码,包括DAO层. MODEL层 .MAPPING SQL映射文件. 第一步: 配置好自动生成代码所需的XML配置文件,例如(generator. ...

  2. Mybatis的generator自动生成代码

    mybatis-generator有三种用法:命令行.ide插件.maven插件.本次使用maven生成 环境:IDEA,mysql8,maven (1):新建项目,本次以SpringBoot项目为例 ...

  3. 【Mybatis】MyBatis之Generator自动生成代码(九)

    MyBatis Generator 简介 MyBatis Generator 连接数据库表并生成MyBatis或iBatis文件.这有助于最大限度地减少使用MyBatis时为数据库文件创建简单CRUD ...

  4. SpringBoot整合Mybatis 使用generator自动生成实体类代码、Mapper代码、dao层代码

    1.新建一个SpringBoot项目,并引入Mybatis和mybatis-generator相关的依赖. <dependency> <groupId>org.springfr ...

  5. MyBatis 使用Generator自动生成Model , Dao, mapper

    最近   我新建了一 个maven 项目,使用的是spring + springmvc + mybatis框架. 听说Mybatis可以自动生成model和mapper以及dao层,我就从网上查了查资 ...

  6. Mybatis使用generator自动生成的Example类使用OR条件查询

    参考:https://blog.csdn.net/qq_36614559/article/details/80354511 public List<AssetsDevicetypeRefacto ...

  7. mybatis利用generator自动生成的代码

    /** * 排序规则 */ protected String orderByClause; /** * 去重规则 */ protected boolean distinct; /** * where条 ...

  8. generator自动生成mybatis配置和类信息

    generator自动生成mybatis的xml配置.model.map等信息: 1.下载mybatis-generator-core-1.3.2.jar包.        网址:http://cod ...

  9. Mybatis generator自动生成mybatis配置和类信息

    自动生成代码方式两种: 1.命令形式生成代码,详细讲解每一个配置参数. 2.Eclipse利用插件形式生成代码. 安装插件方式: eclipse插件安装地址:http://mybatis.google ...

随机推荐

  1. 安卓CPU性能测试

      步骤1.adb shell (进入linux的底层) 步骤2.echo 3>/proc/sys/vm/drop_caches(清除系统cache) 步骤3.top -d 1|grep com ...

  2. cocos学习笔记:快速上手

    cc.Class({ //奇怪的语法风格,cc.class, extends: cc.Component, //扩展自cc.Component properties: { //类的属性设置 jumpH ...

  3. NTFS系统的ADS交换数据流

    VC++ 基于NTFS的数据流创建与检测 What are Alternate Streams?(交换数据流) NTFS alternate streams , 或者叫streams,或者叫ADS(w ...

  4. iOS开发 QQ粘性动画效果

    QQ(iOS)客户端的粘性动画效果 时间 2016-02-17 16:50:00  博客园精华区 原文  http://www.cnblogs.com/ziyi--caolu/p/5195615.ht ...

  5. Lander-Waterman model

    参考: Lander-Waterman Model 这个模型是鸟枪法测序和基因组装的最基本的理论模型,它揭示了测序深度与覆盖度之间的关系. 该模型回答了一个最基本的问题:How many reads ...

  6. Mysql导入导出非常慢解决办法

    MySQL导出的SQL语句在导入时有可能会非常非常慢,经历过导入仅45万条记录,竟用了近3个小时.在导出时合理使用几个参数,可以大大加快导入的速度. -e 使用包括几个VALUES列表的多行INSER ...

  7. [转]IE8兼容Object.keys

    转自:http://blog.sina.com.cn/s/blog_6d63cf160102vbsg.html 只需要加入 var DONT_ENUM = "propertyIsEnumer ...

  8. C++ 指向成员函数指针问题

    成员函数指针与常规指针不同,一个指向成员变量的指针并不指向一个内存位置.通常最清晰的做法是将指向数据成员的指针看作为一个偏移量. class ru_m { public: typedef int (r ...

  9. Balanced Binary Tree [LeetCode]

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...

  10. MySQL之远程登录配置

    1.注释掉mysql配置文件中的这一行:#bind-address  = 127.0.0.1 2.给指定服务器的用户授权:GRANT ALL PRIVILEGES ON *.* TO root@&qu ...