Skip to content

Commit bc3e32b

Browse files
author
hewei
committed
fixed#100:枚举插件正则表达式错误
1 parent 12535ec commit bc3e32b

File tree

4 files changed

+118
-3
lines changed

4 files changed

+118
-3
lines changed

src/main/java/com/itfsw/mybatis/generator/plugins/EnumTypeStatusPlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public class EnumTypeStatusPlugin extends BasePlugin implements ILogicalDeletePl
5050
* 需要生成Enum的Column
5151
*/
5252
public final static String PRO_ENUM_COLUMNS = "enumColumns";
53-
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*.*";
54-
public final static String NEED_PATTERN = "\\[\\s*((\\w+\\s*\\(\\s*[\\u4e00-\\u9fa5_-a-zA-Z0-9]+\\s*\\)\\s*:\\s*[\\u4e00-\\u9fa5_-a-zA-Z0-9]+\\s*\\,?\\s*)+)\\s*\\]";
55-
public final static String ITEM_PATTERN = "(\\w+)\\s*\\(\\s*([\\u4e00-\\u9fa5_-a-zA-Z0-9]+)\\s*\\)\\s*:\\s*([\\u4e00-\\u9fa5_-a-zA-Z0-9]+)";
53+
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*.*";
54+
public final static String NEED_PATTERN = "\\[\\s*((\\w+\\s*\\(\\s*[\\u4e00-\\u9fa5_\\-a-zA-Z0-9]+\\s*\\)\\s*:\\s*[\\u4e00-\\u9fa5_\\-a-zA-Z0-9]+\\s*\\,?\\s*)+)\\s*\\]";
55+
public final static String ITEM_PATTERN = "(\\w+)\\s*\\(\\s*([\\u4e00-\\u9fa5_\\-a-zA-Z0-9]+)\\s*\\)\\s*:\\s*([\\u4e00-\\u9fa5_\\-a-zA-Z0-9]+)";
5656
private Map<String, EnumInfo> enumColumns;
5757

5858
/**

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,26 @@ public void reloadProject(SqlSession sqlSession, ClassLoader loader, String pack
450450
});
451451
}
452452

453+
/**
454+
* 枚举插件无法生成枚举:枚举值为字符串的情况无法生成枚举
455+
* https://github.com/itfsw/mybatis-generator-plugin/issues/100
456+
* @throws Exception
457+
*/
458+
@Test
459+
public void issues100() throws Exception {
460+
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/issues-100.xml");
461+
tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/issues-100.sql"), new AbstractShellCallback() {
462+
@Override
463+
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
464+
// 1. 测试标准注释
465+
ObjectUtil enumField2Success = new ObjectUtil(loader, packagz + ".SysCompany$CompanyStatus#DISABLE");
466+
Assert.assertEquals(enumField2Success.invoke("value"), "disable");
467+
Assert.assertEquals(enumField2Success.invoke("getValue"), "disable");
468+
Assert.assertEquals(enumField2Success.invoke("getName"), "禁用");
469+
}
470+
});
471+
}
472+
453473
/**
454474
* EnumTypeStatusPlugin 支持负数
455475
* https://github.com/itfsw/mybatis-generator-plugin/pull/72
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 `sys_company`;
22+
create table sys_company
23+
(
24+
company_id int auto_increment comment '公司id'
25+
primary key,
26+
company_linkman varchar(64) null comment '联系人名称',
27+
company_name varchar(128) null comment '名称',
28+
company_mobile varchar(11) null comment '手机',
29+
company_email varchar(128) null comment '邮箱',
30+
company_intro varchar(512) null comment '简介',
31+
company_logo varchar(128) null comment 'logo',
32+
company_identity_pic varchar(128) null comment '身份证照片',
33+
company_work_type varchar(45) null comment '工作性质',
34+
company_business_pic varchar(128) null comment '营业执照',
35+
company_status varchar(32) null comment '状态[disable(disable):禁用,deleted(deleted):删除]',
36+
company_create_time timestamp default CURRENT_TIMESTAMP null comment '创建时间',
37+
company_update_time timestamp null comment '更新时间',
38+
column_14 int null
39+
)ENGINE=MyISAM DEFAULT CHARSET=utf8;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright (c) 2018.
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+
<property name="autoDelimitKeywords" value="true"/>
26+
<property name="beginningDelimiter" value="`"/>
27+
<property name="endingDelimiter" value="`"/>
28+
29+
<!-- 插件 -->
30+
<plugin type="com.itfsw.mybatis.generator.plugins.EnumTypeStatusPlugin"/>
31+
32+
<!--jdbc的数据库连接 -->
33+
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
34+
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
35+
targetPackage 指定生成的model生成所在的包名
36+
targetProject 指定在该项目下所在的路径 -->
37+
<javaModelGenerator targetPackage="" targetProject="">
38+
<!-- 是否对model添加 构造函数 -->
39+
<property name="constructorBased" value="true"/>
40+
<!-- 给Model添加一个父类 -->
41+
<!--<property name="rootClass" value="com.itfsw.base"/>-->
42+
</javaModelGenerator>
43+
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
44+
<sqlMapGenerator targetPackage="" targetProject="" />
45+
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
46+
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
47+
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
48+
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
49+
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
50+
51+
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
52+
<table tableName="sys_company" domainObjectName="SysCompany" enableCountByExample="true">
53+
<generatedKey column="company_id" sqlStatement="MySql" identity="true"/>
54+
</table>
55+
</context>
56+
</generatorConfiguration>

0 commit comments

Comments
 (0)