Skip to content

Commit a3dff20

Browse files
author
hewei
committed
官方已修正问题,删除无用代码,增加测试用例
1 parent 2446a75 commit a3dff20

File tree

4 files changed

+114
-13
lines changed

4 files changed

+114
-13
lines changed

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,6 @@ public void tableConfiguration(IntrospectedTable introspectedTable) {
123123
BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateModelAttributes");
124124
BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateXmlAttributes");
125125
}
126-
// TODO 官方bug临时修复
127-
if (tableConfiguration.getDomainObjectRenamingRule() != null) {
128-
StringBuilder domainObjectName = new StringBuilder(fullyQualifiedTable.getDomainObjectName());
129-
// 首字母大写
130-
domainObjectName.setCharAt(0, Character.toUpperCase(domainObjectName.charAt(0)));
131-
BeanUtils.setProperty(fullyQualifiedTable, "domainObjectName", domainObjectName.toString());
132-
133-
// 重新初始化一下属性
134-
BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateJavaClientAttributes");
135-
BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateModelAttributes");
136-
BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateXmlAttributes");
137-
}
138126
// --------------------- column 重命名 ---------------------------
139127
if (tableConfiguration.getColumnRenamingRule() == null
140128
&& this.columnSearchString != null && !this.columnReplaceDisable) {

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,26 @@ public void reloadProject(SqlSession sqlSession, ClassLoader loader, String pack
150150
});
151151
}
152152

153+
/**
154+
* 测试domainObjectRenamingRule和
155+
*/
156+
@Test
157+
public void bug0004() throws Exception {
158+
DBHelper.createDB("scripts/BugFixedTest/bug-0004.sql");
159+
// 规则 ^T 替换成空,也就是去掉前缀
160+
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/bug-0004.xml");
161+
MyBatisGenerator myBatisGenerator = tool.generate();
162+
for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
163+
String name = file.getCompilationUnit().getType().getShortName();
164+
if (!name.matches("B.*")) {
165+
Assert.assertTrue(false);
166+
}
167+
if (name.endsWith("Example")) {
168+
Assert.assertEquals(file.getCompilationUnit().getType().getPackageName(), "com.itfsw.dao.example");
169+
}
170+
}
171+
}
172+
153173
/**
154174
* typeHandler 导致的问题
155175
*/
@@ -370,7 +390,7 @@ public void reloadProject(SqlSession sqlSession, ClassLoader loader, String pack
370390
@Test
371391
public void issues81() throws Exception {
372392
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/issues-81.xml");
373-
MyBatisGenerator myBatisGenerator = tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/issues-81.sql"));
393+
MyBatisGenerator myBatisGenerator = tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/issues-81.sql"));
374394

375395
// 是否在使用系统默认模板
376396
int count = 0;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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-07-05 17:21:41
14+
*/
15+
16+
SET FOREIGN_KEY_CHECKS=0;
17+
18+
-- ----------------------------
19+
-- Table structure for tb
20+
-- ----------------------------
21+
DROP TABLE IF EXISTS `tb_test`;
22+
CREATE TABLE `tb_test` (
23+
`id` bigint(20) NOT NULL COMMENT '注释1',
24+
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
25+
`inc_f2` bigint(20) DEFAULT '0',
26+
`inc_f3` bigint(20) DEFAULT '0',
27+
PRIMARY KEY (`id`)
28+
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
29+
30+
-- ----------------------------
31+
-- Records of tb_test
32+
-- ----------------------------
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
<property name="autoDelimitKeywords" value="true"/>
26+
<property name="beginningDelimiter" value="`"/>
27+
<property name="endingDelimiter" value="`"/>
28+
29+
<!-- Example 目标包修改插件 -->
30+
<plugin type="com.itfsw.mybatis.generator.plugins.ExampleTargetPlugin">
31+
<property name="targetPackage" value="com.itfsw.dao.example"/>
32+
</plugin>
33+
<!-- 表重命名配置插件 -->
34+
<plugin type="com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin">
35+
<property name="domainObjectRenamingRule.searchString" value="^T"/>
36+
<property name="domainObjectRenamingRule.replaceString" value=""/>
37+
</plugin>
38+
39+
<!--jdbc的数据库连接 -->
40+
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
41+
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
42+
targetPackage 指定生成的model生成所在的包名
43+
targetProject 指定在该项目下所在的路径 -->
44+
<javaModelGenerator targetPackage="" targetProject="">
45+
<!-- 是否对model添加 构造函数 -->
46+
<property name="constructorBased" value="true"/>
47+
<!-- 给Model添加一个父类 -->
48+
<!--<property name="rootClass" value="com.itfsw.base"/>-->
49+
</javaModelGenerator>
50+
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
51+
<sqlMapGenerator targetPackage="" targetProject="" />
52+
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
53+
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
54+
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
55+
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
56+
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
57+
58+
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
59+
<table tableName="tb_test"/>
60+
</context>
61+
</generatorConfiguration>

0 commit comments

Comments
 (0)