Eclipse中的安装

1.下载插件

2.将插件generator的features和plugins里的东西都拷贝到eclipse的文件夹features和plugins下。

3.重启eclipse,验证是否安装成功。

Eclipse中的使用

1.新建一个generatorConfig文件

2.generatorConfig.xml文件的配置

  • jdbcConnection ---数据库链接URL、用户名、密码
  • javaModelGenerator---生成模型的包名和位置,就是mybatis 里面用的一些entity 类的存放路径配置
  • sqlMapGenerator ---生成的映射文件报名和位置,就是对应mybatis 的写sql 语句的xml文件的存放路径配置
  • javaClientGenerator---生成DAO的包名和位置,就是mybatis 里面dao 接口的存放路径
  • table---这个配置项是配置在项目中操作的数据库表

(1)pom.xml中添加依赖

(2)运行项目,执行run as -》 maven install 

执行成功后,仓库里会下载下来这些依赖包。(如果有的话,就一直skip然后就build success了)

(3)找到postgresql的jar包位置

这个jar包的位置会在后面的配置文件generatorConfig.xml中用到。

E:\lyh\file\repository\org\postgresql\postgresql\9.4-1206-jdbc41\...
<classPathEntry location="E:\lyh\file\repository\org\postgresql\postgresql\9.4-1206-jdbc41\postgresql-9.4-1206-jdbc41.jar"/>

(4)查看表所在的数据库信息

<jdbcConnection 
        driverClass="org.postgresql.Driver" 
        connectionURL="jdbc:postgresql://10.15.10.14:5432/postgres
        userId="postgres
        password="admin" />

<table tableName="globalpage" domainObjectName="GlobalInfo"/>

(5)配置generatorConfig.xml文件

(6)配置完后运行mybatisConfig.xml

点击mybatisConfig.xml,右键选择generate mybatis ....

(7)查看结果

(8)查看详细代码

疑问:这里有些东西多出来的不知道干嘛~

后来百度知道,这是generator自动生成的example,如果不想要的话,可以在配置文件里配置一下,参看另一篇博文:

2016.7.14 去掉Mybatis Generator生成的一堆 example

还有一个:现在是默认不分页的!还要继续完成分页功能。(可以看到mapper文件里没有分页语句)

IDEA中的安装

pom.xml增加配置,见下面。

IDEA中的使用

先确保数据库连接ok,并且表已经建好。

建表语句:

1.pom.xml中增加mybatis-generator的配置

 1 <build>
2 <finalName>mmall</finalName>
3 <plugins>
4 <plugin>
5 <groupId>org.mybatis.generator</groupId>
6 <artifactId>mybatis-generator-maven-plugin</artifactId>
7 <version>1.3.2</version>
8 <configuration>
9 <verbose>true</verbose>
10 <overwrite>true</overwrite>
11 </configuration>
12 </plugin>
13 ...
14 </build>

2.generatorConfig.xml

新建文件 : src/main/resources/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>
<!--导入属性配置-->
<properties resource="datasource.properties"></properties> <!--指定特定数据库的jdbc驱动jar包的位置-->
<classPathEntry location="${db.driverLocation}"/> <context id="default" targetRuntime="MyBatis3"> <!-- optional,旨在创建class时,对注释进行控制 -->
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator> <!--jdbc的数据库连接 -->
<jdbcConnection
driverClass="${db.driverClassName}"
connectionURL="${db.url}"
userId="${db.username}"
password="${db.password}">
</jdbcConnection> <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver> <!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
targetPackage 指定生成的model生成所在的包名
targetProject 指定在该项目下所在的路径
-->
<!--<javaModelGenerator targetPackage="com.mmall.pojo" targetProject=".\src\main\java">-->
<javaModelGenerator targetPackage="com.mmall.pojo" targetProject="./src/main/java">
<!-- 是否允许子包,即targetPackage.schemaName.tableName -->
<property name="enableSubPackages" value="false"/>
<!-- 是否对model添加 构造函数 -->
<property name="constructorBased" value="true"/>
<!-- 是否对类CHAR类型的列的数据进行trim操作 -->
<property name="trimStrings" value="true"/>
<!-- 建立的Model对象是否 不可改变 即生成的Model对象不会有 setter方法,只有构造方法 -->
<property name="immutable" value="false"/>
</javaModelGenerator> <!--mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
<!--<sqlMapGenerator targetPackage="mappers" targetProject=".\src\main\resources">-->
<sqlMapGenerator targetPackage="mappers" targetProject="./src/main/resources">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator> <!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
--> <!-- targetPackage:mapper接口dao生成的位置 -->
<!--<javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject=".\src\main\java">-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject="./src/main/java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator> <table tableName="mmall_shipping" domainObjectName="Shipping" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_cart" domainObjectName="Cart" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_cart_item" domainObjectName="CartItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_category" domainObjectName="Category" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_order" domainObjectName="Order" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_order_item" domainObjectName="OrderItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_pay_info" domainObjectName="PayInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_product" domainObjectName="Product" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<!-- 数据库的表中这两个字段用的text,mybatis不同版本生成的不一样,所以改为VARCHAR -->
<columnOverride column="detail" jdbcType="VARCHAR" />
<columnOverride column="sub_images" jdbcType="VARCHAR" />
</table>
<table tableName="mmall_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> <!-- geelynote mybatis插件的搭建 -->
</context>
</generatorConfiguration> gerneratorConfig.xml

generatorConfig.xml

重点说明的几个点(其他都采用默认配置):

3.datasource.properties

generatorConfig.xml中用到了datasource.properties,在同目录新增文件datasource.properties。

注意这里的driverLocation:

1 db.driverLocation=E:/lyh/file/repository/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar
2 db.driverClassName=com.mysql.jdbc.Driver
3 db.url=jdbc:mysql://localhost:3306/mmall_learning?characterEncoding=utf-8
4 db.username=root
5 db.password=****

在pom.xml中配置过mysql的驱动,所以只要去maven的本地仓库里找到地址就行:

4.执行mybatis-generator:generate

运行之后:

同样,也是没有分页相关语句的。

2016.7.12 eclipse和IDEA中mybatis generator插件的安装与使用的更多相关文章

  1. eclipse中mybatis generator插件的安装与使用,实现自动生成代码

    git地址:https://github.com/mybatis/generator 下载后解压: 选择任意一个版本的jar放到eclipse的features目录下即可 选择任意一个版本的jar放到 ...

  2. Eclipse 使用mybatis generator插件自动生成代码

    Eclipse 使用mybatis generator插件自动生成代码 标签: mybatis 2016-12-07 15:10 5247人阅读 评论(0) 收藏 举报 .embody{ paddin ...

  3. Eclipse MyBatis Generator插件安装

    目录 Eclipse MyBatis Generator插件安装 Eclipse MyBatis Generator插件安装 1.进入Eclipse Marketplace [Help] -> ...

  4. Myeclipse2014添加mybatis generator插件

    Myeclipse2014把mybatis generator插件直接放在dropins文件夹下,重启后不能成功安装mybatis插件. 既然离线安装不成功,可以选择在线安装 1.选择 Help-&g ...

  5. mybatis generator 插件安装及使用

    现在Mybatis特别火,但是在开发中却要经常写实体类和配置文件,会不会特别烦人,所以可以利用Mybatis的代码生成插件来生成这部分代码: 1,打开eclipse,点击Help>Softwar ...

  6. Mybatis分页-利用Mybatis Generator插件生成基于数据库方言的分页语句,统计记录总数 (转)

    众所周知,Mybatis本身没有提供基于数据库方言的分页功能,而是基于JDBC的游标分页,很容易出现性能问题.网上有很多分页的解决方案,不外乎是基于Mybatis本机的插件机制,通过拦截Sql做分页. ...

  7. Mybatis Generator插件和PageHelper使用

    最近,开始接触web项目开发,项目使用springboot和mybatis,以前一直以为开发过程中实体类,mybatis的xml文件都需要自己手动的去创建. 同事推荐说Mybatis Generato ...

  8. Mybatis-Generator_学习_02_使用Mapper专用的MyBatis Generator插件

    源码见:https://github.com/shirayner/tk-mybatis-generator 一.要点 二.具体实现 1.项目结构 2.配置 pm.xml <?xml versio ...

  9. eclipse在线安装mybatis generator插件

    转自:http://blog.csdn.net/u012283609/article/details/67640433 安装步骤: 打开eclipse菜单栏help–>Eclipse Marke ...

随机推荐

  1. 单元测试-mock基础

    本文较短,只是备份一下mock的几个常用基础例子方便复习 目录 介绍mock的使用例子 maven资源 <dependency> <groupId>org.mockito< ...

  2. Eclipse 4.6(最新版本) js文件不能F3

    解决办法........我是没找到解决4.6版本的办法!不过可以换一个版本!猜想是因为 最新版本强制要求使用jdk1.8所导致的~!  换了一个4.5版本就一切Ok 换上主题一样漂亮护眼

  3. log4net实现多实例记录

    原文地址:实现多个LOG4NET日志记录器实例 本文内容为摘抄,请查看原文. 对于.NET Framework开发者来说,使用Log4Net进行日志记录是非常方便的,通常只要写好配置文件和简单的编码就 ...

  4. Spring MVC请求到处理方法注解配置的几种方式

    @RequestMapping 这个是最常用的注解,可以配置在类上,也可以配置在方法上,两个一起作用组成方法能够响应的请求路径,举例如下 package org.zln.myWeb.controlle ...

  5. Log4j官方文档翻译(一、基本介绍)

    简介 log4j是使用java语言编写的可靠的.快速的.灵活的日志框架,它是基于Apache的license. log4j支持c,c++,c#,perl,python,ruby等语言.在运行时通过额外 ...

  6. 【bzoj3555】[Ctsc2014]企鹅QQ 字符串hash

    题目描述 PenguinQQ是中国最大.最具影响力的SNS(Social Networking Services)网站,以实名制为基础,为用户提供日志.群.即时通讯.相册.集市等丰富强大的互联网功能体 ...

  7. lua源码分析 伪索引

    Lua 提供了一个 注册表, 这是一个预定义出来的表, 可以用来保存任何 C 代码想保存的 Lua 值. 这个表可以用有效伪索引 LUA_REGISTRYINDEX 来定位. 任何 C 库都可以在这张 ...

  8. 十一黄(xun)金(lian)周感想

    实际上并没有训整整一周-_-|| 只训了三天 听说纪中全员没过节(ΩДΩ)好可怕 这三天考了5场模拟赛,一场初赛模拟 让我感觉我和开学时比起来还是有很大的提升的 最主要就是在dp方面. 经过整个九月疯 ...

  9. [usaco jan 09] 气象牛 baric [dp]

    题面: 传送门 思路: 题意有点绕,实际上就是给你一个计算规则,让你取最少的元素,通过这个计算方式,得到一个小于指定误差上限的结果 这个规则分为三个部分,这里分别用pre,sum,suf表示 因为给定 ...

  10. vue中scoped vs css modules

    注意:此文是默认你已经具备scoped和css modules的相关基础知识,所以不做用法上的讲解. 在vue中,我们有两种方式可以定义css作用域,一种是scoped,另一种就是css module ...