Skip to content

Commit 5d219ad

Browse files
author
hewei
committed
Fix #63 : 官方自身问题
1 parent a18d06d commit 5d219ad

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.apache.ibatis.session.SqlSession;
2121
import org.junit.Assert;
2222
import org.junit.Test;
23+
import org.mybatis.generator.api.GeneratedJavaFile;
24+
import org.mybatis.generator.api.MyBatisGenerator;
2325

2426
import java.lang.reflect.Array;
2527
import java.util.List;
@@ -142,4 +144,20 @@ public void reloadProject(SqlSession sqlSession, ClassLoader loader, String pack
142144
}
143145
});
144146
}
147+
148+
/**
149+
* 表重命名配置插件生成的大小写错误
150+
* @throws Exception
151+
*/
152+
@Test
153+
public void issues63() throws Exception {
154+
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/issues-63.xml");
155+
MyBatisGenerator generator = tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/issues-63.sql"));
156+
for (GeneratedJavaFile file : generator.getGeneratedJavaFiles()) {
157+
String fileName = file.getFileName();
158+
if (fileName.startsWith("Repaydetail")){
159+
Assert.assertTrue("官方自己的问题", true);
160+
}
161+
}
162+
}
145163
}

src/test/java/com/itfsw/mybatis/generator/plugins/tools/MyBatisGeneratorTool.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ public MyBatisGenerator generate(AbstractShellCallback callback) throws Exceptio
110110
}, callback);
111111
}
112112

113+
/**
114+
* 执行MyBatisGenerator
115+
* @param before
116+
* @return
117+
* @throws SQLException
118+
* @throws IOException
119+
* @throws InterruptedException
120+
*/
121+
public MyBatisGenerator generate(IBeforeCallback before) throws Exception {
122+
before.run();
123+
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, new DefaultShellCallback(true), warnings);
124+
myBatisGenerator.generate(null, null, null, false);
125+
return myBatisGenerator;
126+
}
127+
113128
/**
114129
* 执行MyBatisGenerator(不生成文件)
115130
* @return
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 `t_repay_detail`;
22+
CREATE TABLE `t_repay_detail` (
23+
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
24+
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
25+
`vs` int DEFAULT NULL,
26+
PRIMARY KEY (`id`)
27+
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
31+
<!--jdbc的数据库连接 -->
32+
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
33+
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
34+
targetPackage 指定生成的model生成所在的包名
35+
targetProject 指定在该项目下所在的路径 -->
36+
<javaModelGenerator targetPackage="" targetProject="">
37+
<!-- 是否对model添加 构造函数 -->
38+
<property name="constructorBased" value="true"/>
39+
<!-- 给Model添加一个父类 -->
40+
<!--<property name="rootClass" value="com.itfsw.base"/>-->
41+
</javaModelGenerator>
42+
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
43+
<sqlMapGenerator targetPackage="" targetProject="" />
44+
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
45+
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
46+
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
47+
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
48+
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
49+
50+
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
51+
<table tableName="t_repay_detail">
52+
<domainObjectRenamingRule searchString="^T" replaceString="" />
53+
</table>
54+
</context>
55+
</generatorConfiguration>

0 commit comments

Comments
 (0)