源码:
<%@ Template Language="C#" TargetLanguage="Text" Src="" Inherits="" Debug="False" CompilerVersion="v3.5" Description="Template descriptiong here." %> <%-- 加载访问数据库的组件SchemaExplorer,并声明其使用的命名空间 --%> <%@ Assembly Name="SchemaExplorer" %> <%@ Import Namespace="SchemaExplorer"%> <%-- 数据库 --%> <%@ Property Name="SourceDatabase" Type="SchemaExplorer.DatabaseSchema" DeepLoad="True" Optional="False"%> <%-- 注册实体层Entity模板 --%> <%@ Register Name="EntityTemplate" Template="ucarEntity.cst" MergeProperties="False" ExcludeProperties=""%> <%-- 注册jsp模板 --%> <%@ Register Name="JspTemplate" Template="jmesa.cst" MergeProperties="False" ExcludeProperties=""%> <%-- 注册sql模板 --%> <%@ Register Name="SqlTemplate" Template="ucarSql.cst" MergeProperties="False" ExcludeProperties=""%> <script runat="template"> // 解决方案输出路径 private string Directory = String.Empty; [Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))] [Optional, NotChecked] [DefaultValue("")] public string OutputDirectory { get {return Directory;} set { if (value.EndsWith("\\")) value = value.Substring(0, value.Length - 1); Directory = value; } } </script> <script runat="template"> // 生成实体Entity类 private void GenerateEntityClasses() { CodeTemplate JavaTemplate = new EntityTemplate(); CodeTemplate JspTemplate = new JspTemplate(); CodeTemplate SqlTemplate = new SqlTemplate(); foreach(TableSchema table in this.SourceDatabase.Tables) { // 生成VO文件 string JavaFile = OutputDirectory + "\\" + table.Name + "VO.java"; // 生成模板 JavaTemplate.SetProperty("Table", table); // 文件输出 JavaTemplate.RenderToFile(JavaFile, true); Debug.WriteLine(JavaFile + "创建成功。"); // 生成Jsp文件 string JspFile = OutputDirectory + "\\" + table.Name + ".jsp"; JspTemplate.SetProperty("Table", table); JspTemplate.RenderToFile(JspFile, true); Debug.WriteLine(JspFile + "创建成功。"); // 生成sql文件 // 用true来指定包含bom string SqlFile = OutputDirectory + "\\" + table.Name + "_sql.xml"; SqlTemplate.SetProperty("Table", table); SqlTemplate.RenderToFile(SqlFile, true); } } </script> <% // 创建实体层Entity类 this.GenerateEntityClasses(); Debug.WriteLine("OK"); %> |