Skip to content

Commit 53e5caa

Browse files
author
hewei
committed
pull#72 测试用例和文档修改,EnumTypeStatusPlugin支持负数
1 parent ab082e8 commit 53e5caa

File tree

4 files changed

+103
-1
lines changed

4 files changed

+103
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ public class Test {
15131513
>warning: 约定的注释检查规则的正则表达式如下
15141514
```java
15151515
public class EnumTypeStatusPlugin {
1516-
public final static String REMARKS_PATTERN = ".*\\s*\\[\\s*(\\w+\\s*\\(\\s*[\\u4e00-\\u9fa5_a-zA-Z0-9]+\\s*\\)\\s*:\\s*[\\u4e00-\\u9fa5_a-zA-Z0-9]+\\s*\\,?\\s*)+\\s*\\]\\s*.*";
1516+
public final static String REMARKS_PATTERN = ".*\\s*\\[\\s*(\\w+\\s*\\(\\s*[\\u4e00-\\u9fa5_-a-zA-Z0-9]+\\s*\\)\\s*:\\s*[\\u4e00-\\u9fa5_-a-zA-Z0-9]+\\s*\\,?\\s*)+\\s*\\]\\s*.*";
15171517
}
15181518

15191519
```

src/test/java/com/itfsw/mybatis/generator/plugins/BugFixedTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,28 @@ public void reloadProject(SqlSession sqlSession, ClassLoader loader, String pack
261261
}
262262
});
263263
}
264+
265+
/**
266+
* EnumTypeStatusPlugin 支持负数
267+
* https://github.com/itfsw/mybatis-generator-plugin/pull/72
268+
* @throws Exception
269+
*/
270+
@Test
271+
public void pull72() throws Exception {
272+
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/pull-72.xml");
273+
tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/pull-72.sql"), new AbstractShellCallback() {
274+
@Override
275+
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
276+
ObjectUtil enumField2Success = new ObjectUtil(loader, packagz + ".Tb$Type#SUCCESS");
277+
Assert.assertEquals(enumField2Success.invoke("value"), (short) 0);
278+
Assert.assertEquals(enumField2Success.invoke("getValue"), (short) 0);
279+
Assert.assertEquals(enumField2Success.invoke("getName"), "成功");
280+
281+
ObjectUtil enumField2FailType = new ObjectUtil(loader, packagz + ".Tb$Type#FAIL");
282+
Assert.assertEquals(enumField2FailType.invoke("value"), (short) -1);
283+
Assert.assertEquals(enumField2FailType.invoke("getValue"), (short) -1);
284+
Assert.assertEquals(enumField2FailType.invoke("getName"), "失败");
285+
}
286+
});
287+
}
264288
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Navicat MySQL Data Transfer
3+
4+
Source Server : localhost
5+
Source Server Version : 50617
6+
Source Host : localhost:3306
7+
Source Database : mybatis-generator-plugin
8+
9+
Target Server Type : MYSQL
10+
Target Server Version : 50617
11+
File Encoding : 65001
12+
13+
Date: 2017-06-27 11:17:08
14+
*/
15+
16+
SET FOREIGN_KEY_CHECKS=0;
17+
18+
-- ----------------------------
19+
-- Table structure for tb
20+
-- ----------------------------
21+
DROP TABLE IF EXISTS `tb`;
22+
CREATE TABLE `tb` (
23+
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
24+
`type` smallint(3) DEFAULT NULL COMMENT '注释[success(0):成功, fail(-1):失败]',
25+
PRIMARY KEY (`id`)
26+
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright (c) 2019.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<!DOCTYPE generatorConfiguration
19+
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
20+
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
21+
<generatorConfiguration>
22+
<properties resource="db.properties"/>
23+
<!--导入属性配置 -->
24+
<context id="default" targetRuntime="MyBatis3">
25+
<!-- 插件 -->
26+
<plugin type="com.itfsw.mybatis.generator.plugins.EnumTypeStatusPlugin"/>
27+
28+
<!--jdbc的数据库连接 -->
29+
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}"/>
30+
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
31+
targetPackage 指定生成的model生成所在的包名
32+
targetProject 指定在该项目下所在的路径 -->
33+
<javaModelGenerator targetPackage="" targetProject="">
34+
<!-- 是否对model添加 构造函数 -->
35+
<property name="constructorBased" value="true"/>
36+
<!-- 给Model添加一个父类 -->
37+
<!--<property name="rootClass" value="com.itfsw.base"/>-->
38+
</javaModelGenerator>
39+
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
40+
<sqlMapGenerator targetPackage="" targetProject=""/>
41+
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
42+
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
43+
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
44+
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
45+
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
46+
47+
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
48+
<table tableName="tb">
49+
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
50+
</table>
51+
</context>
52+
</generatorConfiguration>

0 commit comments

Comments
 (0)