appfuse中生成以S结尾的数据表对应的代码出错的解决方案

appfuse中生成以S结尾的数据表对应的代码出错的解决方案

首先使用appfuse是应该尽量避免以S结尾的单词来作为数据表名,但是很多时候并不是这样的。数据表的名字不能改变的时候我们只能从其他方面想办法了!
在google搜索相关的信息,只找到这一篇文章是有用的,并给予我修改的思路。

http://jira.codehaus.org/browse/MIDDLEGEN-13?page=com.atlassian.jira.plugin.system.issuetabpanels:changehistory-tabpanel
The algorithm for creating singular versions of table names doesn't account for singular words that end in "s". For example, a table called MumbleFooStatus becomes MumbleFooStatu
Suggestion #1: in Util.singularise(), check for a vowel other than "e" before a final "s".

Suggestion #2: change the default behaviour to not singularise tablenames. I think it's bad form for a tool to change the names of my data objects without my consent.

Workarounds: specify table names in build.xml, or if you're using the hibernate plugin, fix the table names in the <dbname>-prefs.properties generated by the plugin and re-run middlegen.

第二点中提到改变middlegen的默认行为让其不去单数化数据表名。

我们要做的有几个步骤(粗略的看了middlegen源码做的修改):
1:下载middlegen源码,下载地址
http://sourceforge.net/project/downloading.php?group_id=36044&use_mirror=jaist&filename=middlegen-2.1-src.zip

http://sourceforge.net/projects/middlegen/files/
2:解压并编辑MiddlegenTask.java中的代码

private static boolean _singularize = true;
改成
private static boolean _singularize = false;
3:重新编译并打包成jar,在middlegen的根目录下输入命令行命令:ant jar即可
4:将新的middlegen-2.1.jar替换目标项目(已生成)中extras\middlegen\lib\middlegen-2.1的middlegen-2.1.jar
这样,在生成以S结尾的数据表名对应的代码就不会出错了!
但是这样做始终有不好的地方:在表示对象复数的地方就会出现不尽人意的代码了,但是不管怎么样,代码还是生成出来了,后期的工作就可以依靠手动去修改。
所以还是尽量去遵循不以S结尾的单词作为数据表名。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值