采用velocity根据模块自动生成java类
<div style="padding-right: 5.4pt; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 4px; width: 95%; padding-top: 4px;">http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport java.io.BufferedWriter;http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport java.io.File;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport java.io.FileWriter;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport java.io.IOException;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport java.io.StringWriter;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport java.util.Properties;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport org.apache.velocity.Template;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport org.apache.velocity.VelocityContext;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport org.apache.velocity.app.VelocityEngine;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gifpublic class Test ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif private static Properties props = null;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif /** *//**
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif * @param args
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif * @throws Exception
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif */
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif public static void main(String[] args) throws Exception ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif // TODO Auto-generated method stub
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif /**//* first, get and initialize an engine */
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif VelocityEngine ve = new VelocityEngine();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif ve.init();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif /**//* next, get the Template */
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Template t = ve.getTemplate( "src/Action.vm","gb2312" );
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif // Template t = ve.getTemplate( "src/Action.vm" );
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif //如果改为上面则出现乱码.
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif /**//* create a context and add data */
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif VelocityContext context = new VelocityContext();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Object[] classNames=null;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif// classNames.add("Jgss");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif// classNames.add("Jgfs");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif// classNames.add("Tcfj");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif classNames=prop2List();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif for(int i=0;i<classNames.length;i++ )...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif context.put("className", classNames);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif /**//* now render the template into a StringWriter */
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif StringWriter writer = new StringWriter();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif t.merge( context, writer );
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif writeJavaFile(classNames+"Action.java",writer.toString());
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif /**//* show the World */
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif // System.out.println( writer.toString() );
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif private static void writeJavaFile(String name, String str) ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif try ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif FileWriter fw = new FileWriter(new File(name), true);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif BufferedWriter bw = new BufferedWriter(fw);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif // 将读入的字符串写入到文件中
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif bw.write(str, 0, str.length());
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif bw.flush();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif bw.close();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif fw.close();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif } catch (IOException e) ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif System.out.println("Error-- :" + e.toString());
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif private static void loadProperties()...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif props = new Properties();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif try ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif props.load(Test.class.getResourceAsStream("action.properties"));
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif } catch (IOException e) ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif // TODO Auto-generated catch block
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif e.printStackTrace();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif private static Object[] prop2List()...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif loadProperties();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif System.out.println(props.size());
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif if(props.isEmpty()) return null;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Object[] aa = props.values().toArray();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif return aa;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif 部分Action.vm代码:
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gifpublic ActionForward edit$...{className}(ActionMapping mapping, ActionForm form,
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif HttpServletRequest request, HttpServletResponse response)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif throws Exception ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif logger.debug("--- edit${className} start ---");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif checkToken(request);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif $...{className}Form $...{className.toLowerCase()}Form = ($...{className}Form)form;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifaction.properties:
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifA=Jaaas
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifB=Jbbbs
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifC=Tcccs
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
页:
[1]