开发学院软件开发Java 动态表单及动态建表实现原理 阅读

动态表单及动态建表实现原理

 2009-09-22 00:00:00 来源:WEB开发网   
核心提示: FormGenerator : 创建访问数据库Groovy代码publicclassFormGenerator{protectedMaproot=newHashMap();privatestaticLoggerlog=LoggerFactory.getLogger(FormGenerator.c

FormGenerator : 创建访问数据库Groovy代码

public class FormGenerator {
    protected  Map root = new HashMap();
    private static Logger log = LoggerFactory.getLogger(FormGenerator.class);
        protected String path ;
        protected String packageName ;
        private Form form ; 
        protected Configuration getConfig(String resource) {
            
             Configuration cfg = new Configuration();
            cfg.setDefaultEncoding("UTF-8");
            cfg.setClassForTemplateLoading(this.getClass(), resource);
            return cfg;
        }
        
        public FormGenerator(Form form){
            this.form = form;
        }
        
        public String generator(){
            String returnstr = null;
            Template t;
            try {
                t = getConfig("/template").getTemplate("FormService.ftl");
                //Writer out = new OutputStreamWriter(new FileOutputStream(new File(path)),"UTF-8");
                Writer out = new StringWriter();
                t.process(getMapContext(), out);
                returnstr = out.toString();
                log.debug(returnstr);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (TemplateException e) {
                e.printStackTrace();
            }
            return returnstr;
        }
        
        @SuppressWarnings("unchecked")
        Map getMapContext() {
            root.put("entity", form);
            root.put("insert", SqlHelper.buildInsertStatement(form));
            root.put("update", SqlHelper.buildUpdateStatement(form));
            
            root.put("insertParameter", SqlHelper.buildInsertparameter(form));
            root.put("updateParameter", SqlHelper.buildUpdateparameter(form));
            
            root.put("delete", SqlHelper.buildDeleteStatement(form));
            root.put("query",  SqlHelper.buildQueryStatement(form));    
            return root;
        }
}

上一页  1 2 3 4 5  下一页

Tags:动态 表单 动态

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接