Skip to content

Commit 8aad55a

Browse files
author
hewei
committed
bugfix[issues#36]:ExampleEnhancedPlugin在列比较时对于typeHandler处理有问题
1 parent 4aab608 commit 8aad55a

File tree

4 files changed

+103
-10
lines changed

4 files changed

+103
-10
lines changed

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
import java.util.List;
1515

16-
import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
17-
1816
/**
1917
* ---------------------------------------------------------------------------
2018
* Example 增强插件
@@ -130,14 +128,7 @@ private Method generateSingleValueMethod(IntrospectedTable introspectedTable, In
130128

131129
// 方法体
132130
sb.setLength(0);
133-
if (stringHasValue(introspectedColumn.getTypeHandler())) {
134-
sb.append("add");
135-
sb.append(introspectedColumn.getJavaProperty());
136-
sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
137-
sb.append("Criterion(");
138-
} else {
139-
sb.append("addCriterion(");
140-
}
131+
sb.append("addCriterion(");
141132
sb.append("new StringBuilder(\"");
142133
sb.append(MyBatis3FormattingUtilities.getAliasedActualColumnName(introspectedColumn));
143134
sb.append(" ");

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ public void reloadProject(SqlSession sqlSession, ClassLoader loader, String pack
108108
});
109109
}
110110

111+
/**
112+
* typeHandler 导致的问题
113+
*/
114+
@Test
115+
public void issues36() throws Exception {
116+
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/issues-36.xml");
117+
tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/issues-36.sql"), new AbstractShellCallback() {
118+
@Override
119+
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
120+
// Example 编译报错
121+
new ObjectUtil(loader, packagz + ".TbExample");
122+
}
123+
});
124+
}
125+
111126
/**
112127
* 乐观锁插件好像变量作用域问题导致,前一个表的配置会影响后一个表配置
113128
*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
25+
`t_date` date DEFAULT NULL,
26+
PRIMARY KEY (`id`)
27+
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
<!-- 数据Model属性对应Column获取插件 -->
30+
<plugin type="com.itfsw.mybatis.generator.plugins.ModelColumnPlugin"/>
31+
<!-- Selective选择插入更新增强插件 -->
32+
<plugin type="com.itfsw.mybatis.generator.plugins.SelectiveEnhancedPlugin"/>
33+
<!-- Example Criteria 增强插件 -->
34+
<plugin type="com.itfsw.mybatis.generator.plugins.ExampleEnhancedPlugin"/>
35+
36+
<!--jdbc的数据库连接 -->
37+
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
38+
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
39+
targetPackage 指定生成的model生成所在的包名
40+
targetProject 指定在该项目下所在的路径 -->
41+
<javaModelGenerator targetPackage="" targetProject="">
42+
<!-- 是否对model添加 构造函数 -->
43+
<property name="constructorBased" value="true"/>
44+
<!-- 给Model添加一个父类 -->
45+
<!--<property name="rootClass" value="com.itfsw.base"/>-->
46+
</javaModelGenerator>
47+
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
48+
<sqlMapGenerator targetPackage="" targetProject="" />
49+
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
50+
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
51+
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
52+
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
53+
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
54+
55+
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
56+
<table tableName="tb">
57+
<columnOverride column="field1" javaType="java.sql.Array" typeHandler="org.apache.ibatis.type.ArrayTypeHandler"/>
58+
</table>
59+
</context>
60+
</generatorConfiguration>

0 commit comments

Comments
 (0)