From 6e132d7dc2ee72f00ec69897792c22e72913fe7d Mon Sep 17 00:00:00 2001 From: hewei Date: Wed, 11 Jan 2017 18:44:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0README.md=E4=BB=8B=E7=BB=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++- pom.xml | 1 + 2 files changed, 152 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a6a77d..1b6e9fd 100644 --- a/README.md +++ b/README.md @@ -1 +1,151 @@ -# mybatis-generator-plugin \ No newline at end of file +# 这是 MyBatis Generator 插件的拓展插件包 +应该说使用Mybatis就一定离不开[MyBatis Generator](https://github.com/mybatis/generator)这款代码生成插件,而这款插件自身还提供了插件拓展功能用于强化插件本身,官方已经提供了一些拓展插件([详情](http://www.mybatis.org/generator/reference/plugins.html)),本项目的目的也是通过该插件机制来强化Mybatis Generator本身,方便和减少我们平时的代码开发量。 +因为插件是本人兴之所至所临时发布的项目(本人已近三年未做JAVA开发,代码水平请大家见谅),但基本插件都是在实际项目中经过检验的请大家放心使用,但因为项目目前主要数据库为MySQL,Mybatis实现使用Mapper.xml方式,所以代码生成时对于其他数据库和注解方式的支持未予考虑,请大家见谅。 +--------------------------------------- +插件列表: ++ 查询单条数据插件 ++ MySQL分页插件 ++ 数据Model链式构建插件 ++ 查询条件链式构建插件 +--------------------------------------- +### 1. 查询单条数据插件 +对应表Mapper接口增加了方法 +插件: +```xml + + +``` +使用: +```java +public interface TbMapper { + /** + * 这是Mybatis Generator拓展插件生成的方法(请勿删除). + * This method corresponds to the database table tb + * + * @mbg.generated + * @author hewei + */ + Tb selectOneByExample(TbExample example); +} +``` +### 2. MySQL分页插件 +对应表Example类增加了方法 +插件: +```xml + + +``` +使用: +```java +public class TbExample { + /** + * 这是Mybatis Generator拓展插件生成的属性(请勿删除). + * This field corresponds to the database table tb + * + * @mbg.generated + * @author hewei + */ + protected Integer offset; + + /** + * 这是Mybatis Generator拓展插件生成的属性(请勿删除). + * This field corresponds to the database table tb + * + * @mbg.generated + * @author hewei + */ + protected Integer rows; + /** + * 这是Mybatis Generator拓展插件生成的方法(请勿删除). + * This method corresponds to the database table rc_user_token + * + * @mbg.generated + * @author hewei + */ + public void limit(Integer rows) { + this.rows = rows; + } + + /** + * 这是Mybatis Generator拓展插件生成的方法(请勿删除). + * This method corresponds to the database table rc_user_token + * + * @mbg.generated + * @author hewei + */ + public void limit(Integer offset, Integer rows) { + this.offset = offset; + this.rows = rows; + } + + /** + * 这是Mybatis Generator拓展插件生成的方法(请勿删除). + * This method corresponds to the database table tb + * + * @mbg.generated + * @author hewei + */ + public void page(Integer page, Integer pageSize) { + this.offset = page * pageSize; + this.rows = pageSize; + } + + // offset 和 rows 的getter&setter + + // 修正了clear方法 + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table tb + * + * @mbg.generated + */ + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + rows = null; + offset = null; + } +} +``` +### 3. 数据Model链式构建插件 +这个是仿jquery的链式调用强化了表的Model的赋值操作 +插件: +```xml + + +``` +使用: +```java +public class Test { + public static void main(String[] args) { + // 直接new表Model的内部Builder类,赋值后调用build()方法返回对象 + Tb table = new Tb.Builder() + .field1("xx") + .field2("xx") + .field3("xx") + .field4("xx") + .build(); + } +} +``` +### 4. 数据Model链式构建插件 +表Example增加Criteria的快速快速构建方式 +插件: +```xml + + +``` +使用: +```java +public class Test { + public static void main(String[] args) { + // 表Example.Criteria增加了工厂方法example()和链式构建支持,使用后可链式构建查询条件使用example()返回Example对象 + TbExample ex = new TbExample() + .createCriteria() + .andField1EqualTo(1) + .andField2LessThan(100) + .example(); + } +} +``` \ No newline at end of file diff --git a/pom.xml b/pom.xml index c4c1025..d1bcaf5 100644 --- a/pom.xml +++ b/pom.xml @@ -184,6 +184,7 @@ http://central.sonatype.org/pages/working-with-pgp-signatures.html http://www.cnblogs.com/gaoxing/p/4359795.html http://blog.csdn.net/ssrc0604hx/article/details/51513414 + http://www.trinea.cn/dev-tools/upload-java-jar-or-android-aar-to-maven-center-repository/ -->