appfuse中生成以S結(jié)尾的數(shù)據(jù)表對(duì)應(yīng)的代碼出錯(cuò)的解決方案
首先使用appfuse是應(yīng)該盡量避免以S結(jié)尾的單詞來(lái)作為數(shù)據(jù)表名,但是很多時(shí)候并不是這樣的。數(shù)據(jù)表的名字不能改變的時(shí)候我們只能從其他方面想辦法了!在google搜索相關(guān)的信息,只找到這一篇文章是有用的,并給予我修改的思路。
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.
第二點(diǎn)中提到改變middlegen的默認(rèn)行為讓其不去單數(shù)化數(shù)據(jù)表名。
我們要做的有幾個(gè)步驟(粗略的看了middlegen源碼做的修改):
1:下載middlegen源碼,下載地址
http://sourceforge.net/project/downloading.php?group_id=36044&use_mirror=jaist&filename=middlegen-2.1-src.zip
2:解壓并編輯MiddlegenTask.java中的代碼
把
private static boolean _singularize = true;
改成
private static boolean _singularize = false;
3:重新編譯并打包成jar,在middlegen的根目錄下輸入命令行命令:ant jar即可
4:將新的middlegen-2.1.jar替換目標(biāo)項(xiàng)目(已生成)中extras\middlegen\lib\middlegen-2.1的middlegen-2.1.jar
這樣,在生成以S結(jié)尾的數(shù)據(jù)表名對(duì)應(yīng)的代碼就不會(huì)出錯(cuò)了!
但是這樣做始終有不好的地方:在表示對(duì)象復(fù)數(shù)的地方就會(huì)出現(xiàn)不盡人意的代碼了,但是不管怎么樣,代碼還是生成出來(lái)了,后期的工作就可以依靠手動(dòng)去修改。
所以還是盡量去遵循不以S結(jié)尾的單詞作為數(shù)據(jù)表名。
Let life be beautiful like summer flowers and death like autumn leaves.
posted on 2008-06-07 09:28 Alexwan 閱讀(370) 評(píng)論(0) 編輯 收藏