读书人

mybatis (Ibatis ibator) generator -

发布时间: 2012-09-01 09:33:03 作者: rapoo

mybatis (Ibatis ibator) generator - 1 mysql 分页插件(page/paging/pagination plugin)

?

前言

在线文档,参考?http://ibatis.apache.org/docs/tools/ibator/

由于ibatis转移为mybatis,所以参考mybatis 最新文档:http://code.google.com/p/mybatis/wiki/Downloads?tm=2

下载的MyBatis Generator Tool中有文档说明

?

http://ibatis.apache.org/docs/tools/ibator/reference/pluggingIn.html

将plugin的生命周期和怎么扩展,都已经交代明了,接下来就是动手实践了

How to

1 Plugin Class?

生成plugin class, ?extends PluginAdapter.?如同文档所说,直接implements Plugin 接口会很繁琐,超多的方法要实现。

?

?

?

?

targetRuntime我们选择Ibatis2Java5而不是MyBatis3,因为在后面的?javaClientGenerator中我们希望使用Spring DAO

?

If the <context> targetRuntime is?MyBatis3:XMLMAPPERThe generated objects will be Java interfaces for the MyBatis 3.x mapper infrastructure. The interfaces will be dependent on generated XML mapper files.If the <context> targetRuntime is?Ibatis2Java2?or?Ibatis2Java5:IBATISThe generated objects will conform to the (deprecated) iBATIS DAO framework.GENERIC-CIThe generated objects will rely only on the SqlMapClient. The SqlMapClient will be supplied by constructor dependency injection. The generated objects will be in the form of DAO interfaces amd implementation classes.GENERIC-SIThe generated objects will rely only on the SqlMapClient. The SqlMapClient will be supplied by setter dependency injection. The generated objects will be in the form of DAO interfaces amd implementation classes.SPRINGThe generated objects will conform to the Spring DAO framework.

?

?

?

3)?<plugin type="org.leef.db.mybatis.plugin.PaginationPlugin" />

?? ? 添加我们使用的插件 ? ??

?

生成的sql map selectByExample 如下

?

dao.selectByExample(example);???

?

?

OK, 大功告成,so easy, rt?

关于mybatis generator 的故事并没有完结,后文中我们将会介绍

1) Spring DAO和 Mapper class 的区别

2) 如何handle 常量表(cache 常用表)

3) 如何handle column default value

读书人网 >Mysql

热点推荐