所需的资源: mybatis-generator-core-1.3.2.jar,MySQL-connector-Java-5.1.22-bin.jar。mybatis-generator-core-1.3.2.jar,官网访问太慢,你懂的。故已将jar文件免费上传,自行下载。

MyBatis :是支持定制化 SQL、存储过程以及高级映射的优秀的持久层框架。MyBatis 避免了几乎所有的 JDBC 代码和手工设置参数以及抽取结果集。MyBatis 使用简单的 XML 或注解来配置和映射基本体,将接口和 Java 的 POJOs(Plain Old JavaObjects,普通的 Java对象)映射成数据库中的记录。

1、建立数据库表,新建文件夹src,存放文件。

2、创建XML配置文件generator.xml,使用的是mysql数据库。

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
  3. <generatorConfiguration >
  4. <!-- classPathEntry用于设置数据库驱动包位置-->
  5. </pre><pre code_snippet_id="485664" snippet_file_name="blog_20141016_1_6249858" name="code" class="html">
  6. <classPathEntry location="E:\ssh\lib\mybatis\mysql-connector-java-5.1.22-bin.jar"/>
  7. <!-- targetRuntime:代码生成目标,默认是MyBatis3-->
  8. <context id="DB2Tables" targetRuntime="MyBatis3">
  9. <commentGenerator>
  10. <property name="suppressAllComments" value="true"/>
  11. </commentGenerator>
  12. <!-- 数据库连接的信息 -->
  13. <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/test" userId="root" password="">
  14. </jdbcConnection>
  15. <!-- 解决数据转换问题 -->
  16. <javaTypeResolver>
  17. <!--是否强制使用BigDecimal来表示所有的十进制和数值字段。-->
  18. <property name="forceBigDecimals" value="false" />
  19. </javaTypeResolver>
  20. <!--生成模型的包名和位置-->
  21. <javaModelGenerator targetPackage="project.model" targetProject="E:\ssh\lib\mybatis\src">
  22. <property name="enableSubPackages" value="true" />
  23. <property name="trimStrings" value="true" />
  24. </javaModelGenerator>
  25. <!--生成的映射文件包名和位置-->
  26. <sqlMapGenerator targetPackage="project.mapping" targetProject="E:\ssh\lib\mybatis\src">
  27. <property name="enableSubPackages" value="true" />
  28. </sqlMapGenerator>
  29. <!--生成DAO的包名和位置-->
  30. <javaClientGenerator type="XMLMAPPER" targetPackage="project.dao" targetProject="E:\ssh\lib\mybatis\src">
  31. <property name="enableSubPackages" value="true" />
  32. </javaClientGenerator>
  33. <!--要生成那些文件-->
  34. <!--<table tableName="表名"  domainObjectName="类名"></table>-->
  35. <table tableName="t_user" domainObjectName="User"  enableCountByExample="false" enableUpdateByExample="false"
  36. enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  37. </context>
  38. </generatorConfiguration>

3、执行jar文件。相同目录下执行命令行语句:java -jarmybatis-generator-core-1.3.2.jar -configfile -generator.xml

4、MyBatis Generator finished successfully.完成。

初学:利用mybatis-generator自动生成代码的更多相关文章

  1. SpringBoot 添加mybatis generator 自动生成代码插件

    自动生成数据层代码,提高开发效率 1.pom添加插件,并指定配置文件路径 <!-- mybatis generator 自动生成代码插件 --> <plugin> <gr ...

  2. idea中mybatis generator自动生成代码配置 数据库是sqlserver

    好长时间没有写博客了,最近公司要用java语言,开始学习java,属于初学者,今天主要记录一下mybatis generator自动生成代码,首先在如下图的目录中新建两个文件,如下图 generato ...

  3. SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件

    原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...

  4. IDEA Maven Mybatis generator 自动生成代码

    IDEA Maven Mybatis generator 自动生成代码 一.安装配置maven以及在Idea中配置maven 安装过程步骤可以看上面的博文,里面介绍得很详细. 二.建数据表 DROP ...

  5. IDEA Maven Mybatis generator 自动生成代码(实例讲解)(转)

    IDEA Maven Mybatis generator 自动生成代码(实例讲解) MyBatis Generator • 简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器,可以快速的 ...

  6. 使用Mybatis Generator自动生成代码

    MyBatis Generator(MBG)是MyBatis MyBatis 和iBATIS的代码生成器.它将为所有版本的MyBatis以及版本2.2.0之后的iBATIS版本生成代码.它将内省数据库 ...

  7. Mybatis generator 自动生成代码(2)

    最近准备开始做一个项目,需要开始手动创建sql,于是将Mybatis generator 工具功能强化了下. 首先,这里引入到版本一点的包 <dependency> <groupId ...

  8. Mybatis generator 自动生成代码

    开发项目的时候,表很多,是不可能一点点的自己去写xml ,dao文件的,这里就需要用到代码的自动生成工具了. 第一步:导入jar包,当然,这之前,基本环境,像mybatis,数据库之类的都得搭建好. ...

  9. IDEA使用mybatis generator自动生成代码

    主要就三步: 1.pom 文件中引入jar包并配置 build 属性 <dependencies> <!-- 自动生产mapper Begin! --> <depende ...

  10. mybatis generator自动生成代码时 只生成了insert 而没有其他的

    mybatis框架提供了非常好用的逆向工程插件,但是在使用过程中会有很多问题. 我在使用中就遇到了只生成insert和insertSeletive方法,而不生成其他根据primary key查询更新删 ...

随机推荐

  1. Android 5.0状态栏和导航栏

    Material Design推出之后,app中也開始沿用这样的风格 今天来说一下状态栏颜色设置,在4.4的时候推出了透明状态栏和导航栏.在不使用第三方库的情况下,4.4还是没有全然解决存在actio ...

  2. idea自动注入和自动编译

    ---恢复内容开始--- 自动编译也就是时时编译,当我们写错代码的时候,idea能够马上报错,这个是不错的功能. 安装操作看下图: 下面这个功能的作用就是,如果你不修改的话,你的项目可以正常运行,但是 ...

  3. caffe2--ubuntu16.04--14.04--install

    Install Welcome to Caffe2! Get started with deep learning today by following the step by step guide ...

  4. AQS实现公平锁和非公平锁

    https://www.cnblogs.com/chengdabelief/p/7493200.html AQS(AbstractQueuedSynchronizer类)是一个用来构建锁和同步器的框架 ...

  5. Python标准库:内置函数set([iterable])

    本函数是从迭代对象生成集合.集合能够添加或删除元素. 样例: #set() tset = set([1, 2, 3, 3, 4, 5, 6, 6]) print(tset) tset.add(20) ...

  6. 问题 “cell 出栈 selectBox 已选的图标,被释放掉,再次进入屏幕时,没有了已选图标 ” 解决方案

    如何 去解决 列表里面的selectBox已选情况,在滑出屏幕后被清除的问题.      我来在这里 详细说明一下, 在cell里面写一个方法,去专门修复滑出后,又滑进来 图标被冲刷掉的cell. 在 ...

  7. types of transfrmations

    http://math.wallawalla.edu/~duncjo/courses/math113/winter08/notes/9-1_math113.pdf Name What Changes ...

  8. 一起来学linux:PAM模块

    在Linux中执行有些程序时,这些程序在执行前首先要对启动它的用户进行认证,符合一定的要求之后才允许执行,例如login, su等 在Linux中进行身份或是状态的验证程序是由PAM来进行的,PAM( ...

  9. platform_set_drvdata和platform_get_drvdata用法【转】

    本文转载自:http://www.cnblogs.com/wangxianzhen/archive/2013/04/09/3009530.html 在用到Linux设备驱动的platform框架时,常 ...

  10. poj3904 Sky Code —— 唯一分解定理 + 容斥原理 + 组合

    题目链接:http://poj.org/problem?id=3904 Sky Code Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...