日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

采用velocity根據(jù)模塊自動(dòng)生成java類

系統(tǒng) 3152 0

import ?java.io.BufferedWriter;
import ?java.io.File;
import ?java.io.FileWriter;
import ?java.io.IOException;
import ?java.io.StringWriter;
import ?java.util.Properties;
import ?org.apache.velocity.Template;
import ?org.apache.velocity.VelocityContext;
import ?org.apache.velocity.app.VelocityEngine;

public ? class ?Test? ... {
????
private ? static ?Properties?props? = ? null ;????
????
/**?*/ /**
?????*?
@param ?args
?????*?
@throws ?Exception?
?????
*/

????
public ? static ? void ?main(String[]?args)? throws ?Exception? ... {
????????
// ?TODO?Auto-generated?method?stub
???????? /**/ /* ?first,?get?and?initialize?an?engine? */
??????????VelocityEngine?ve?
= ? new ?VelocityEngine();
??????????ve.init();
??????????
/**/ /* ?next,?get?the?Template? */
??????????Template?t?
= ?ve.getTemplate(? " src/Action.vm " , " gb2312 " ?);??
????????
// ??????????Template?t?=?ve.getTemplate(?"src/Action.vm"?);
??????????
// 如果改為上面則出現(xiàn)亂碼.
??????????
??????????
/**/ /* ?create?a?context?and?add?data? */
??????????VelocityContext?context?
= ? new ?VelocityContext();
??????????Object[]?classNames
= null ;
// ??????????????classNames.add("Jgss");
// ??????????????classNames.add("Jgfs");
// ??????????????classNames.add("Tcfj");
??????????classNames = prop2List();
??????????
for ( int ?i = 0 ;i < classNames.length;i ++ ?) ... {
??????????context.put(
" className " ,?classNames[i]);

??????????
/**/ /* ?now?render?the?template?into?a?StringWriter? */
??????????StringWriter?writer?
= ? new ?StringWriter();
??????????t.merge(?context,?writer?);
??????????
??????????writeJavaFile(classNames[i]
+ " Action.java " ,writer.toString());
????????
??????????
/**/ /* ?show?the?World? */
?????????
// ?System.out.println(?writer.toString()?);?
??????????}

????}

????
????
????
private ? static ? void ?writeJavaFile(String?name,?String?str)? ... {
????????
try ? ... {
????????????FileWriter?fw?
= ? new ?FileWriter( new ?File(name),? true );
????????????BufferedWriter?bw?
= ? new ?BufferedWriter(fw);

????????????
// ?將讀入的字符串寫入到文件中
????????????bw.write(str,? 0 ,?str.length());
????????????bw.flush();
????????????bw.close();
????????????fw.close();
????????}
? catch ?(IOException?e)? ... {
????????????System.out.println(
" Error--?: " ? + ?e.toString());
????????}

????}


????
private ? static ? void ?loadProperties() ... {
????????props?
= ? new ?Properties();
????????
try ? ... {
????????????props.load(Test.
class .getResourceAsStream( " action.properties " ));
????????}
? catch ?(IOException?e)? ... {
????????????
// ?TODO?Auto-generated?catch?block
????????????e.printStackTrace();
????????}

????}

????
????
private ? static ?Object[]?prop2List() ... {
????????loadProperties();
????????System.out.println(props.size());
????????
if (props.isEmpty())?? return ? null ;
????????Object[]?aa?
= ?props.values().toArray();
????????
return ?aa;
????}

????
????
}




?部分Action.vm代碼:

public ?ActionForward?edit$ ... {className} (ActionMapping?mapping,?ActionForm?form,
???HttpServletRequest?request,?HttpServletResponse?response)
???
throws ?Exception? ... {

??logger.debug(
" ---?edit${className}?start?--- " );
??checkToken(request);
??$
... {className} Form?$ ... {className.toLowerCase()} Form? = ?($ ... {className} Form)form;

action.properties:

A
= Jaaas
B
= Jbbbs
C
= Tcccs

采用velocity根據(jù)模塊自動(dòng)生成java類


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會(huì)非常 感謝您的哦!?。?/p>

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 喀什市| 平山县| 大厂| 平安县| 榆树市| 星座| 罗城| 茌平县| 孝昌县| 富源县| 和顺县| 堆龙德庆县| 沐川县| 金华市| 高邑县| 邵武市| 叙永县| 鹤岗市| 洪江市| 黄骅市| 谷城县| 嘉义县| 沁水县| 沂水县| 徐闻县| 桂林市| 泾阳县| 曲松县| 韩城市| 来宾市| 铜梁县| 镇安县| 德格县| 申扎县| 福泉市| 尉氏县| 武强县| 龙里县| 瑞安市| 卓尼县| 衡阳县|