首页 技术 正文
技术 2022年11月12日
0 收藏 314 点赞 4,169 浏览 1405 个字

使用domainObjectRenamingRule报错

在使用MyBatis逆向工程时报错如下:

org.mybatis.generator.exception.XMLParserException: XML Parser Error on line 43: 必须声明元素类型 "domainObjectRenamingRule"。
at org.mybatis.generator.config.xml.ConfigurationParser.parseConfiguration(ConfigurationParser.java:121)
at org.mybatis.generator.config.xml.ConfigurationParser.parseConfiguration(ConfigurationParser.java:82)
at org.mybatis.generator.config.xml.ConfigurationParser.parseConfiguration(ConfigurationParser.java:74)
at GeneratorSqlmap.generator(GeneratorSqlmap.java:22)
at GeneratorSqlmap.main(GeneratorSqlmap.java:32)

domainObjectRenamingRule该功能项是在MBG 1.3.6中新增加的功能,用于定义实体的重命名规则,常见的用途是取消表前缀。类似于columnRenamingRule,前者是重命名生成的模型对象的名称,后者是重命名表字段的名称。

如果在低于该版本的MBG中使用该功能,会出现如下错误XML Parser Error on line 59: 必须声明元素类型 "domainObjectRenamingRule"。

使用domainObjectRenamingRule无效

配置好了domainObjectRenamingRule后,运行逆向工程却无效果,原因是searchString的值配置不对。

根据表名来生成的类名是按照驼峰命名法,生成的类名首字母是大写的。而searchString是区分大小写的,并且它的值是Java里的正则表达式。

举个例子,现在有个表叫tb_vq,我希望生成的类名是Vq,而不是TbVq,可以通过domainObjectRenamingRule来实现这个功能,配置如下:

<table tableName="tb_vq" schema="" enableCountByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false">
<domainObjectRenamingRule searchString="^Tb" replaceString="" />
</table>

需要注意的是,这里的searchString必须填^Tb,这是个Java正则表达式,这里不能写成^tb,必须首字母大写,否则匹配不上,另外为了避免匹配出错,这里使用了^Tb而不是Tb

参考链接

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,401
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,813
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,896